Castor Marshalling error due to race condition (version 1.3.x)
If you are using Castor for Object to XML mapping, you may have encountered exceptions like
Nested error: org.exolab.castor.xml.MarshalException: White space is required between the processing instruction target and data.{File: [not available]; line: 1; column: 10}
pool-1-thread-20org.castor.mapping.MappingUnmarshaller.loadMappingInternal(MappingUnmarshaller.java:282)
org.castor.mapping.MappingUnmarshaller.getMappingLoader(MappingUnmarshaller.java:155)
org.castor.mapping.MappingUnmarshaller.getMappingLoader(MappingUnmarshaller.java:130)
org.exolab.castor.xml.Marshaller.setMapping(Marshaller.java:628)
Original issue is the mapping file is being shared by many threads.
To fix this we can use castor 1.4.X or consider creating ThreadLocal instances of
ThreadLocal<Mapping> localMapping = new ThreadLocal<Mapping>() {
@Override
protected Mapping initialValue() {
//retry 3 times
try {
return createMapping();
} catch (Exception e) {
logError(e);
}
};
Nested error: org.exolab.castor.xml.MarshalException: White space is required between the processing instruction target and data.{File: [not available]; line: 1; column: 10}
pool-1-thread-20org.castor.mapping.MappingUnmarshaller.loadMappingInternal(MappingUnmarshaller.java:282)
org.castor.mapping.MappingUnmarshaller.getMappingLoader(MappingUnmarshaller.java:155)
org.castor.mapping.MappingUnmarshaller.getMappingLoader(MappingUnmarshaller.java:130)
org.exolab.castor.xml.Marshaller.setMapping(Marshaller.java:628)
Original issue is the mapping file is being shared by many threads.
To fix this we can use castor 1.4.X or consider creating ThreadLocal instances of
ThreadLocal<Mapping> localMapping = new ThreadLocal<Mapping>() {
@Override
protected Mapping initialValue() {
//retry 3 times
try {
return createMapping();
} catch (Exception e) {
logError(e);
}
};
Comments
Post a Comment