Details
-
Bug
-
Status: Resolved
-
Minor
-
Resolution: Fixed
-
Version 2
-
None
Description
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.
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
1836 catch (ClassNotFoundException e)
1837
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
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.