Nested unmarshalling can lead to NullPointerException #937
Description
The attached ZIP contains a Maven project with two test cases.
For this issue, the classes, resources and test case in package com.jaxbtest.java7.bug2 are relevant.
To reproduce:
1.) make sure your current test environment is Java 7 Update 10
For Maven 2.2.1 on Windows it means:
a) set the JAVA_HOME variable to your Java 7 Update 10 JDK installation directory.
b) prepend %JAVA_HOME%\bin to your Path.
2.) run the unit tests in the project
For Maven 2.2.1 it means:
a) execute "mvn test" in the project root directory
b) examine test result (look at ./target/surefire-reports/com.jaxbtest.java7.bug2.UnternehmenTestCase.txt)
It should fail with a NullPointerException.
Coordinator._getInstance() returns null at some point in the stacktrace, so the error reporting fails too.
You have to debug the test in an IDE to see the real cause. You can import the project into Eclipse (m2e required!) for that.
Some observations about the error cause:
Class Unternehmen is the XmlRootElement. It has a list of Branche-elements, which are handled by the BrancheXmlAdapter.
During unmarshall the adapter uses a BrancheConverter helper class. This class in turn loads a XML document via JAXB.
So we have a nested unmarshalling scenario in the same thread. When the nested umnmarshalling ends, Coordinator.resetThreadAffinity() is called. Later, when the second Branche is unmarshalled from the adapted list of Unternehmen, Coordinator._getInstance() returns null in
AdaptedLister#getAdapter()
com.jaxbtest.java7.bug2.UnternehmenTestCase is the entrypoint for the test.
I think it also fails for JAXB 2.2.6.
It works with Java 6 Update 35 for example.
Environment
Java 7 Update 10 on Windows 7
Affected Versions
[2.2.4u2]