XMLBeans
  1. XMLBeans
  2. XMLBEANS-478

NullPointerException in SchemaType.getEnumJavaClass

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: Version 2
    • Fix Version/s: None
    • Component/s: XmlObject, XPath

      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.

      { 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.

        Activity

        Hide
        Cezar Andrei added a comment -

        Fixed with rev: 1241699. Thanks for your contribution Martin.

        Show
        Cezar Andrei added a comment - Fixed with rev: 1241699. Thanks for your contribution Martin.

          People

          • Assignee:
            Cezar Andrei
            Reporter:
            Martin McCallion
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development