Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
Version 2, Version 2.1, Version 2.2
-
None
Description
We have seen this NPE during normal use of our application on a MP Solaris system using XmlBeans 2.0.0. I tested and confirmed it is still a problem in 2.2.0:
java.lang.NullPointerException
at org.apache.xmlbeans.SchemaComponent$Ref.getComponent(SchemaComponent.java:104)
at org.apache.xmlbeans.SchemaType$Ref.get(SchemaType.java:872)
at org.apache.xmlbeans.impl.schema.SchemaPropertyImpl.getType(SchemaPropertyImpl.java:92)
at org.apache.xmlbeans.impl.schema.SchemaTypeImpl.createElementType(SchemaTypeImpl.java:965)
at org.apache.xmlbeans.impl.values.XmlObjectBase.create_element_user(XmlObjectBase.java:895)
at org.apache.xmlbeans.impl.store.Xobj.getUser(Xobj.java:1592)
at org.apache.xmlbeans.impl.store.Cur.getUser(Cur.java:2627)
at org.apache.xmlbeans.impl.store.Cur.getObject(Cur.java:2620)
at org.apache.xmlbeans.impl.store.Cursor._getObject(Cursor.java:983)
at org.apache.xmlbeans.impl.store.Cursor.getObject(Cursor.java:2896)
Here is how to reproduce with the debugger:
- start two threads, each of which loads a different xml document with the same schema type
- each thread will traverse its document, calling getObject at each element
- break before traversal starts
- insert breakpoint at SchemaComponent.java:104, and let both threads run to this point
- resume one thread, and then the other
- the second thread fails with the NPE
Here is the code fragment from SchemaComponent $Ref:
public final SchemaComponent getComponent()
{
if (_schemaComponent == null && _handle != null)
return _schemaComponent;
}
Both threads use the same Ref object, and there is no protection between use of _schemaTypeSystem on line 104 and setting it null on the next line
I do not know enough about how thread protection of schema types is designed to know if a localized fix to synchronize the lazy instantiation is appropriate, or if synchronization at a higher level is appropriate.