Announcement Announcement Module
No announcement yet.
NPE with StaxEventWriter's Result object Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • NPE with StaxEventWriter's Result object

    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 id="filesMarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller">

    And in our step the writer fails with this:

        at org.springframework.batch.item.xml.StaxEventItemWriter.write(

    Line 573 & 574 of StaxEventWriter
    Result result = StaxUtils.getResult(eventWriter);
    		marshaller.marshal(object, result );
    Line 105 of AbstractMarshaller after failing some instanceof checks on result as it is probably null:
    throw new IllegalArgumentException("Unknown Result type: " + result.getClass())
    And this line then throws an NPE as you cant access .getClass() on a null object.

    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:

    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;
    staxUtilsResultMethodOnSpring30 seems to be invoke a createStaxResult method on XMLEventWriter? (Line 78 of StaxUtils). This is where my reflection knowledge suffers.

    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?

  • #2
    As StaxEventItemWriter can not be used as it always throws NullPointerException we are currently rewriting this to a custom item writer to marshal to xml and append to a file.

    Shame, as StaxEventItemWriter seemed such a clean way of doing it