- Code: Select all
java.lang.NullPointerException
at org.docx4j.wml.Id.hashCode(Id.java:129)
at java.util.HashMap.put(Unknown Source)
at com.sun.xml.bind.v2.runtime.AssociationMap.addInner(AssociationMap.java:78)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.recordInnerPeer(UnmarshallingContext.java:1025)
at com.sun.xml.bind.v2.runtime.unmarshaller.StructureLoader.startElement(StructureLoader.java:147)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:402)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:380)
at com.sun.xml.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(InterningXmlVisitor.java:35)
at com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:101)
at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:224)
:
at com.sun.xml.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:83)
at com.sun.xml.bind.v2.runtime.BinderImpl.associativeUnmarshal(BinderImpl.java:140)
at com.sun.xml.bind.v2.runtime.BinderImpl.unmarshal(BinderImpl.java:111)
at org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart.unmarshal(MainDocumentPart.java:249)
Hi, I can reproduce the error when I use JAXB 2.1.2 via
- Code: Select all
-Djava.endorsed.dirs="c:\\JAXB\\2.1.2\\lib"
That's quite old, dating from 2007. Are you able to use a newer version of JAXB?
(You seem to have JAXB2_20100510.jar and jaxb-impl-2.1.2.jar. If JAXB2_20100510.jar is a new JAXB, can you remove the old jaxb-impl-2.1.2.jar from your path?)
My code for an sdt/content control id hashcode is:
- Code: Select all
public int hashCode() {
return val.intValue();
}
Your NPE is occuring because BigInteger val is null - it looks like this is being triggered for each sdt in the document (even though they have proper ids)
I'm not sure what to do in this case. I could return some other int, but this might result in problems in downstream code which stores sdt in a hashmap. So I'm inclined to leave the code as is.
If you must use JAXB 2.1.2, some variation on
- Code: Select all
public int hashCode() {
if (val==null) {
System.out.println("** Null id val");
return Math.abs(new java.util.Random().nextInt());
}
return val.intValue();
}
allows CustomXmlBinding sample to run