Uploaded image for project: 'Cocoon'
  1. Cocoon
  2. COCOON-2077

XModuleSource getInputStream() throws NPE

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.1.9, 2.1.10, 2.1.11, 2.2
    • 2.1.11, 2.2
    • * Cocoon Core
    • None

    Description

      I'm getting:

      java.lang.NullPointerException
      at org.apache.cocoon.serialization.AbstractTextSerializer.getTransformerHandler(AbstractTextSerializer.java:138)
      at org.apache.cocoon.serialization.XMLSerializer.setOutputStream(XMLSerializer.java:53)
      at org.apache.cocoon.components.source.impl.XModuleSource.getInputStream(XModuleSource.java:196)
      at com.researchresearch.cocoon.generation.RESTfulServiceGenerator.doPOSTBody(RESTfulServiceGenerator.java:323)
      at com.researchresearch.cocoon.generation.RESTfulServiceGenerator.generate(RESTfulServiceGenerator.java:276)
      at org.apache.cocoon.components.pipeline.AbstractProcessingPipeline.processXMLPipeline(AbstractProcessingPipeline.java:579)
      at org.apache.cocoon.components.pipeline.AbstractProcessingPipeline.process(AbstractProcessingPipeline.java:780)
      at org.apache.cocoon.components.source.impl.SitemapSource.toSAX(SitemapSource.java:414)
      at org.apache.cocoon.components.source.SourceUtil.toSAX(SourceUtil.java:101)
      at org.apache.cocoon.components.source.SourceUtil.parse(SourceUtil.java:321)
      at org.apache.cocoon.sitemap.ContentAggregator.generate(ContentAggregator.java:125)
      ...

      When trying to use an xmodule: as the source for a custom generator.

      [Cocoon BRANCH_2_1_X.]

      Now admittedly, I'm not using it in a pure sitemap way, which would end up using the XMLizable interface method, but I'm calling the (equally valid) Source method getInputStream() instead.

      The offending code in org.apache.cocoon.components.source.impl.XModuleSource seems to be:

          /**
           * Return an <code>InputStream</code> object to read from the source.
           *
           * @throws IOException if I/O error occured.
           */
          // Stolen from QDoxSource
          public InputStream getInputStream() throws IOException, SourceException {
              if ( this.logger.isDebugEnabled() ) {
                  this.logger.debug( "Getting InputStream for " + getURI() );
              }

              // Serialize the SAX events to the XMLSerializer:

              XMLSerializer serializer = new XMLSerializer(); <!--- HERE: creates XMLSerializer, but doesn't configure() it !! -->
              ByteArrayInputStream inputStream = null;

              try {
                  ByteArrayOutputStream outputStream = new ByteArrayOutputStream( 2048 );
                  serializer.setOutputStream( outputStream );
                  toSAX( serializer );
                  inputStream = new ByteArrayInputStream( outputStream.toByteArray() );
              } catch ( SAXException se ) {
                  logger.error( "SAX exception!", se );
                  throw new SourceException( "Serializing SAX to a ByteArray failed!", se );
              }

              return inputStream;
          }

      The serializer is created, but not configure()d, and it is only the configuration that sets the TransformerFactory in AbstractTextSerializer.java, hence the NPE.

      The causal change seems to have been made to AbstractTextSerializer yonks ago:

      23784 3/19/03 5:37PM sylvain Allow the TransformerFactory class to be specified in the configuration

      Before that revision the TransformerFactory was set in the constructor of AbstractTextSerializer, thus it worked with the xmodule getInputStream() method before that change.

      No compensating change is in XModuleSource (433543), so this has been broken since 2003.

      Attachments

        Activity

          People

            joerg.heinicke@gmx.de Jörg Heinicke
            ellispritchard Ellis Pritchard
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: