NullPointerException in SchemaType.getEnumJavaClass
---------------------------------------------------

                 Key: XMLBEANS-478
                 URL: https://issues.apache.org/jira/browse/XMLBEANS-478
             Project: XMLBeans
          Issue Type: Bug
          Components: XmlObject, XPath
    Affects Versions: Version 2
            Reporter: Martin McCallion
            Priority: Minor


I have code like this, where currentElement is an XmlObject:

        // Check whether we're dealing with an enumeration.
        Class fieldClass;
        SchemaType t = currentElement.schemaType();
        if (t.getEnumJavaClass() != null)  // According the JavaDoc, should 
return null if it's not an enum.
        {
            fieldClass = currentElement.schemaType().getEnumJavaClass();
        }
        else
        {
            fieldClass = currentElement.getClass();
        }


This throws a NullPointerException as follows:

[27/01/12 14:02:27:526 GMT] 00000030 SystemOut     O E Exception caught within 
struts
java.lang.NullPointerException
        at 
org.apache.xmlbeans.impl.schema.SchemaTypeImpl.getEnumJavaClass(SchemaTypeImpl.java:1835)
        at 
com.misys.meridian.runtime.message.XmlMessageImpl.setFieldValue(XmlMessageImpl.java:711)
        at 
com.misys.meridian.runtime.message.XmlMessageImpl.setField(XmlMessageImpl.java:950)
        at 
com.misys.meridian.runtime.message.XmlMessageImpl.setField(XmlMessageImpl.java:989)
...

I found source for SchemaTypeImpl here: 
http://www.docjar.com/html/api/org/apache/xmlbeans/impl/schema/SchemaTypeImpl.java.html.
  The method in question looks like this (line numbers provided at that link):

 1829       public Class getEnumJavaClass()
 1830       {
 1831           // This field is declared volatile and Class is immutable so 
this is allowed.
 1832           if (_javaEnumClass == null)
 1833           {
 1834               try
 1835                   { _javaEnumClass = 
Class.forName(getBaseEnumType().getFullJavaName() + "$Enum", false, 
getTypeSystem().getClassLoader()); }
 1836               catch (ClassNotFoundException e)
 1837                   { _javaEnumClass = null; }
 1838           }
 1839   
 1840           return _javaEnumClass;
 1841       }
 
 Line 1835 could NPE if getBaseEnumType() returns null.  And indeed, elsewhere 
in the same class we see:

1465       public SchemaType getBaseEnumType()
 1466       {
 1467           return _baseEnumTyperef == null ? null : _baseEnumTyperef.get();
 1468       }

Which suggests that that is exactly what's happening.

It is, of course, possible that I have done something wrong in creating my 
generated classes, such that they are missing some necessary data.  But if that 
is so, there ought to be a more informative Exception.  And note that the 
classes were generated using scomp from an ISO20022 schema.

I'm working around this by checking for a null return on getEnumerationValues() 
instead.





--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to