users@glassfish.java.net

NullPointerException when trying to persist a half-filled Character array

From: <glassfish_at_javadesktop.org>
Date: Mon, 21 Jan 2008 04:10:44 PST

I tried to search the Issue Tracker and this forum and could not find anything about the following problem, but it seems too obvious to be a bug in Toplink so I'm asking on the mailing list first.

In my JPA application I have an entity with a field of Character[]. I populate it not completely (i.e. some elements are null) and persist the entity. At commit time the transaction is rolled back with a NullPointerException:

[i][TopLink Warning]: 2008.01.21 08:17:15.109--UnitOfWork(33459432)--Exception [TOPLINK-3001] (Oracle TopLink Essentials - 2.0.1 (Build SNAPSHOT (01/21/2008))): oracle.toplink.essentials.exceptions.ConversionException
Exception Description: The object [[Ljava.lang.Character;@19cd75a], of class [class [Ljava.lang.Character;], could not be converted to [class java.lang.String].

Internal Exception: java.lang.NullPointerException
(...)
Caused by: java.lang.NullPointerException
        at oracle.toplink.essentials.internal.helper.ConversionManager.convertObjectToCharArray(ConversionManager.java:394)
        at oracle.toplink.essentials.internal.helper.ConversionManager.convertObjectToString(ConversionManager.java:650)
        at oracle.toplink.essentials.internal.helper.ConversionManager.convertObject(ConversionManager.java:129)
        ... 39 more[/i]

It happens in the following code:
        if (sourceObject instanceof Character[]) {
            Character[] objectChars = (Character[])sourceObject;
            char[] chars = new char[objectChars.length];
            for (int index = 0; index < objectChars.length; index++) {
                chars{index} = objectChars{index}.charValue(); <- NPE occurs here
            }
            return chars;
        }

#I replaced the normal brackets with curly brackets because with the normal brackets the Preview of this message gets garbled.

This is called from convertObjectToString, which includes a comment saying "Bug#3854296 Added support to convert Byte[], char[] and Character[] to String correctly".
I could find no information about this bug.
I can make a test application to reproduce this. Should I open a bug?
[Message sent by forum member 'dkoper' (dkoper)]

http://forums.java.net/jive/thread.jspa?messageID=254962