Hi we are getting an unexplained NullPointerException in StaxEventItemWriter.
Our Xml looks something like this:
HTML Code:<bean id="blahWriter" class="org.springframework.batch.item.xml.StaxEventItemWriter" scope="step"> <property name="resource" value="file:///C:/blah/blah/blah.tmp"/> <property name="rootTagName" value="root" /> <property name="overwriteOutput" value="true" /> <property name="marshaller" ref="filesMarshaller" /> </bean> <bean id="filesMarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller"> ....
And in our step the writer fails with this:
Code:java.lang.NullPointerException at org.springframework.oxm.support.AbstractMarshaller.marshal(AbstractMarshaller.java:105) at org.springframework.batch.item.xml.StaxEventItemWriter.write(StaxEventItemWriter.java:574)
Line 573 & 574 of StaxEventWriter
Line 105 of AbstractMarshaller after failing some instanceof checks on result as it is probably null:Code:Result result = StaxUtils.getResult(eventWriter); marshaller.marshal(object, result );
And this line then throws an NPE as you cant access .getClass() on a null object.Code:throw new IllegalArgumentException("Unknown Result type: " + result.getClass())
At first wasted alot of time wondering if StaxUtils.getResult method could not detect Spring environment (line 116-126 of StaxUtils), but it now more seems the invoke call fails to create a Result object. I think. Line 117 of StaxUtils:
staxUtilsResultMethodOnSpring30 seems to be invoke a createStaxResult method on XMLEventWriter? (Line 78 of StaxUtils). This is where my reflection knowledge suffers.Code:if (hasSpring30StaxSupport) { Object result = staxUtilsResultMethodOnSpring30.invoke(null,w); Assert.isInstanceOf(Result.class, result, "the result should be assignable to " + Result.class.getName()); return (Result) result;
Code:staxUtilsResultMethodOnSpring30 = ClassUtils.getStaticMethod(clzz, "createStaxResult", new Class[]{XMLEventWriter.class});
Any ideas of what can cause our stax step not to create a proper Result object?


Reply With Quote
