Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Awkward NullPointerException in Xalan transformations

843834Aug 3 2004 — edited Aug 5 2004
L.S,

I'm having a serious problem with XSL transformations using Apache Xalan 2.6.0: a transformation works once, but multiple calls to the method will cause a null-pointer exception to occur within the TrAXFilter object taking care of the transformation.

The class responsible for transforming any XML messages in our system looks like this (class MessageWriter appearing at line 14 is a JAXB marshalling class we've developed; class FilterManager appearing at line 21 returns an array of 1 hard-coded XMLFilter object):
 
public class MessageBuilder {
  private final static SAXParserFactory XML_PARSER = SAXParserFactory.newInstance();
  
  public static String getXmlMessage(MessageSDO message) {
    String xml = MessageWriter.doMarshal(message);
    
    try {
      SAXParser parser = XML_PARSER.newSAXParser();
      XMLReader reader = XMLReaderFactory.createXMLReader();
      
      InputSource srcInput = new InputSource(new StringReader(xml));
      FilterManager ftrManager = (FilterManager) ConfigurationManager.
        getInstance(ConfigurationManager.BOUNDARY).getBean(FilterManager.class);
      
      XMLFilter[] filters = ftrManager.getOutputFilters(message);
      if (filters.length > 0) {
        for (int i=0;i<filters.length;i++) {
          filters.setParent((i==0)? reader : filters[i-1]);
}

Serializer serializer = SerializerFactory.getSerializer(OutputPropertiesFactory.getDefaultMethodProperties("xml"));
ByteArrayOutputStream output = new ByteArrayOutputStream();
serializer.setOutputStream(output);
filters[filters.length-1].setContentHandler(serializer.asContentHandler());

filters[filters.length-1].parse(srcInput);
xml = output.toString();
}
} catch (Exception e) {
throw new RuntimeException(e);
}

return xml;
}
}


The test I've run (if 2nd block commented out test succeeds, otherwise it fails on that 2nd attempt):
public void testTransformedOutput() {
  System.out.println("Transformed output test:\n\n");
  MessageSDO msg = MockSDOFactory.getInstance().getMessageSDO();
  String xmlMsg = MessageBuilder.getXmlMessage(msg);
        
  /*System.out.println("Transformed output test, 2nd pass:\n\n");
    MessageSDO msg2 = MockSDOFactory.getInstance().getMessageSDO();
    String xmlMsg2 = MessageBuilder.getXmlMessage(msg2);*/
}
The exception message:
java.lang.RuntimeException: java.lang.NullPointerException
at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:658)
at org.apache.crimson.parser.Parser2.parse(Parser2.java:334)
at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:448)
at org.apache.xalan.transformer.TrAXFilter.parse(TrAXFilter.java:134)
at org.boundary.helper.MessageBuilder.getXmlMessage(MessageBuilder.java:36)
  
// Line 36 in MessageBuilder is:
// filters[filters.length-1].parse(srcInput);
What I don't yet understand is how TrAXFilter manages to somehow not have a parent in the 2nd pass of the test, while it does in the 1st pass. I've tried a few things already, but so far haven't been able to find a solution.

Does anyone know of a bug like this? Or is it clear to someone what I'm doing completely wrong here? I'd appreciate any help you can offer.

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Sep 2 2004
Added on Aug 3 2004
1 comment
632 views