Uploaded image for project: 'Batik'
  1. Batik
  2. BATIK-945

NullPointerException in DataBufferInt.getBankData()

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Resolution: Unresolved
    • Affects Version/s: 1.7
    • Fix Version/s: None
    • Component/s: SVG Rasterizer
    • Labels:
      None
    • Environment:
      Operating System: Mac OS X 10.5
      Platform: PC

      Description

      I'm using the Transcoder API to rasterize an SVG into JPEG. I'm getting the following NPE, followed by a complete crash of the Java VM (there's two stack traces here - I'm not sure if it happened twice on two separate images or if these are related somehow):

      java.lang.NullPointerException
      at java.awt.image.DataBufferInt.getBankData(DataBufferInt.java:162)
      at org.apache.batik.ext.awt.image.rendered.PadRed$ZeroRecter_INT_PACK.<init>(PadRed.java:156)
      at org.apache.batik.ext.awt.image.rendered.PadRed$ZeroRecter.getZeroRecter(PadRed.java:123)
      at org.apache.batik.ext.awt.image.rendered.PadRed.handleZero(PadRed.java:193)
      at org.apache.batik.ext.awt.image.rendered.PadRed.copyData(PadRed.java:92)
      at org.apache.batik.ext.awt.image.rendered.ColorMatrixRed.copyData(ColorMatrixRed.java:116)
      at org.apache.batik.ext.awt.image.rendered.FormatRed.copyData(FormatRed.java:116)
      at org.apache.batik.ext.awt.image.rendered.AbstractRed.getData(AbstractRed.java:526)
      at org.apache.batik.ext.awt.image.GraphicsUtil.drawImage(GraphicsUtil.java:264)
      at org.apache.batik.ext.awt.image.GraphicsUtil.drawImage(GraphicsUtil.java:455)
      at org.apache.batik.ext.awt.image.renderable.PadRable8Bit.paintRable(PadRable8Bit.java:135)
      at org.apache.batik.ext.awt.image.GraphicsUtil.drawImage(GraphicsUtil.java:440)
      at org.apache.batik.ext.awt.image.renderable.PadRable8Bit.paintRable(PadRable8Bit.java:135)
      at org.apache.batik.ext.awt.image.GraphicsUtil.drawImage(GraphicsUtil.java:440)
      at org.apache.batik.ext.awt.image.renderable.FilterChainRable8Bit.paintRable(FilterChainRable8Bit.java:251)
      at org.apache.batik.ext.awt.image.GraphicsUtil.drawImage(GraphicsUtil.java:440)
      at org.apache.batik.gvt.AbstractGraphicsNode.paint(AbstractGraphicsNode.java:549)
      at org.apache.batik.gvt.CompositeGraphicsNode.primitivePaint(CompositeGraphicsNode.java:165)
      at org.apache.batik.gvt.AbstractGraphicsNode.paint(AbstractGraphicsNode.java:509)
      at org.apache.batik.gvt.CompositeGraphicsNode.primitivePaint(CompositeGraphicsNode.java:165)
      at org.apache.batik.gvt.filter.GraphicsNodeRed8Bit.genRect(GraphicsNodeRed8Bit.java:140)
      at org.apache.batik.gvt.filter.GraphicsNodeRed8Bit.copyData(GraphicsNodeRed8Bit.java:116)
      at org.apache.batik.ext.awt.image.rendered.PadRed.copyData(PadRed.java:88)
      at org.apache.batik.ext.awt.image.rendered.AbstractRed.getData(AbstractRed.java:526)
      at org.apache.batik.ext.awt.image.rendered.Any2LumRed.copyData(Any2LumRed.java:71)
      at org.apache.batik.ext.awt.image.rendered.AbstractRed.getData(AbstractRed.java:526)
      at org.apache.batik.ext.awt.image.rendered.FilterAsAlphaRed.copyData(FilterAsAlphaRed.java:83)
      at org.apache.batik.ext.awt.image.rendered.AbstractRed.getData(AbstractRed.java:526)
      at org.apache.batik.ext.awt.image.rendered.MultiplyAlphaRed.INT_PACK_BYTE_COMP_Impl(MultiplyAlphaRed.java:107)
      at org.apache.batik.ext.awt.image.rendered.MultiplyAlphaRed.copyData(MultiplyAlphaRed.java:183)
      at org.apache.batik.ext.awt.image.rendered.Any2sRGBRed.copyData(Any2sRGBRed.java:166)
      at org.apache.batik.ext.awt.image.rendered.FormatRed.copyData(FormatRed.java:116)
      at org.apache.batik.ext.awt.image.GraphicsUtil.drawImage(GraphicsUtil.java:347)
      at org.apache.batik.ext.awt.image.GraphicsUtil.drawImage(GraphicsUtil.java:455)
      at org.apache.batik.gvt.AbstractGraphicsNode.paint(AbstractGraphicsNode.java:549)
      at org.apache.batik.gvt.CompositeGraphicsNode.primitivePaint(CompositeGraphicsNode.java:165)
      at org.apache.batik.gvt.AbstractGraphicsNode.paint(AbstractGraphicsNode.java:509)
      at org.apache.batik.gvt.CompositeGraphicsNode.primitivePaint(CompositeGraphicsNode.java:165)
      at org.apache.batik.gvt.AbstractGraphicsNode.paint(AbstractGraphicsNode.java:509)
      at org.apache.batik.gvt.CompositeGraphicsNode.primitivePaint(CompositeGraphicsNode.java:165)
      at org.apache.batik.gvt.AbstractGraphicsNode.paint(AbstractGraphicsNode.java:509)
      at org.apache.batik.gvt.CompositeGraphicsNode.primitivePaint(CompositeGraphicsNode.java:165)
      at org.apache.batik.gvt.AbstractGraphicsNode.paint(AbstractGraphicsNode.java:509)
      at org.apache.batik.gvt.CompositeGraphicsNode.primitivePaint(CompositeGraphicsNode.java:165)
      at org.apache.batik.gvt.CanvasGraphicsNode.primitivePaint(CanvasGraphicsNode.java:159)
      at org.apache.batik.gvt.AbstractGraphicsNode.paint(AbstractGraphicsNode.java:509)
      at org.apache.batik.gvt.CompositeGraphicsNode.primitivePaint(CompositeGraphicsNode.java:165)
      at org.apache.batik.gvt.AbstractGraphicsNode.paint(AbstractGraphicsNode.java:509)
      at org.apache.batik.gvt.renderer.MacRenderer.repaint(MacRenderer.java:361)
      at org.apache.batik.gvt.renderer.MacRenderer.repaint(MacRenderer.java:291)
      at org.apache.batik.transcoder.image.ImageTranscoder.transcode(ImageTranscoder.java:111)
      at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(XMLAbstractTranscoder.java:142)
      at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:156)
      at com.dji.converter.epub.constructor.ImageConstructor.convertVectorImage(ImageConstructor.java:305)
      at com.dji.converter.epub.constructor.ImageConstructor.createImage(ImageConstructor.java:109)
      at com.dji.converter.epub.constructor.ImageConstructor.handleStartEvent(ImageConstructor.java:80)
      at com.dji.converter.epub.ePubConverter.processEvents(ePubConverter.java:334)
      at com.dji.converter.epub.ePubConverter.convert(ePubConverter.java:202)
      at com.dji.converter.ConverterBase.run(ConverterBase.java:91)
      at java.lang.Thread.run(Thread.java:613)
      java.lang.NullPointerException
      at java.awt.image.DataBufferInt.getBankData(DataBufferInt.java:162)
      at org.apache.batik.ext.awt.image.rendered.PadRed$ZeroRecter_INT_PACK.<init>(PadRed.java:156)
      at org.apache.batik.ext.awt.image.rendered.PadRed$ZeroRecter.getZeroRecter(PadRed.java:123)
      at org.apache.batik.ext.awt.image.rendered.PadRed.handleZero(PadRed.java:193)
      at org.apache.batik.ext.awt.image.rendered.PadRed.copyData(PadRed.java:92)
      at org.apache.batik.ext.awt.image.rendered.ColorMatrixRed.copyData(ColorMatrixRed.java:116)
      at org.apache.batik.ext.awt.image.rendered.FormatRed.copyData(FormatRed.java:116)
      at org.apache.batik.ext.awt.image.rendered.AbstractRed.getData(AbstractRed.java:526)
      at org.apache.batik.ext.awt.image.GraphicsUtil.drawImage(GraphicsUtil.java:264)
      at org.apache.batik.ext.awt.image.GraphicsUtil.drawImage(GraphicsUtil.java:455)
      at org.apache.batik.ext.awt.image.renderable.PadRable8Bit.paintRable(PadRable8Bit.java:135)
      at org.apache.batik.ext.awt.image.GraphicsUtil.drawImage(GraphicsUtil.java:440)
      at org.apache.batik.ext.awt.image.renderable.PadRable8Bit.paintRable(PadRable8Bit.java:135)
      at org.apache.batik.ext.awt.image.GraphicsUtil.drawImage(GraphicsUtil.java:440)
      at org.apache.batik.ext.awt.image.renderable.FilterChainRable8Bit.paintRable(FilterChainRable8Bit.java:251)
      at org.apache.batik.ext.awt.image.GraphicsUtil.drawImage(GraphicsUtil.java:440)
      at org.apache.batik.gvt.AbstractGraphicsNode.paint(AbstractGraphicsNode.java:549)
      at org.apache.batik.gvt.CompositeGraphicsNode.primitivePaint(CompositeGraphicsNode.java:165)
      at org.apache.batik.gvt.AbstractGraphicsNode.paint(AbstractGraphicsNode.java:509)
      at org.apache.batik.gvt.CompositeGraphicsNode.primitivePaint(CompositeGraphicsNode.java:165)
      at org.apache.batik.gvt.filter.GraphicsNodeRed8Bit.genRect(GraphicsNodeRed8Bit.java:140)
      at org.apache.batik.gvt.filter.GraphicsNodeRed8Bit.copyData(GraphicsNodeRed8Bit.java:116)
      at org.apache.batik.ext.awt.image.rendered.PadRed.copyData(PadRed.java:88)
      at org.apache.batik.ext.awt.image.rendered.AbstractRed.getData(AbstractRed.java:526)
      at org.apache.batik.ext.awt.image.rendered.Any2LumRed.copyData(Any2LumRed.java:71)
      at org.apache.batik.ext.awt.image.rendered.AbstractRed.getData(AbstractRed.java:526)
      at org.apache.batik.ext.awt.image.rendered.FilterAsAlphaRed.copyData(FilterAsAlphaRed.java:83)
      at org.apache.batik.ext.awt.image.rendered.AbstractRed.getData(AbstractRed.java:526)
      at org.apache.batik.ext.awt.image.rendered.MultiplyAlphaRed.INT_PACK_BYTE_COMP_Impl(MultiplyAlphaRed.java:107)
      at org.apache.batik.ext.awt.image.rendered.MultiplyAlphaRed.copyData(MultiplyAlphaRed.java:183)
      at org.apache.batik.ext.awt.image.rendered.Any2sRGBRed.copyData(Any2sRGBRed.java:166)
      at org.apache.batik.ext.awt.image.rendered.FormatRed.copyData(FormatRed.java:116)
      at org.apache.batik.ext.awt.image.GraphicsUtil.drawImage(GraphicsUtil.java:347)
      at org.apache.batik.ext.awt.image.GraphicsUtil.drawImage(GraphicsUtil.java:455)
      at org.apache.batik.gvt.AbstractGraphicsNode.paint(AbstractGraphicsNode.java:549)
      at org.apache.batik.gvt.CompositeGraphicsNode.primitivePaint(CompositeGraphicsNode.java:165)
      at org.apache.batik.gvt.AbstractGraphicsNode.paint(AbstractGraphicsNode.java:509)
      at org.apache.batik.gvt.CompositeGraphicsNode.primitivePaint(CompositeGraphicsNode.java:165)
      at org.apache.batik.gvt.AbstractGraphicsNode.paint(AbstractGraphicsNode.java:509)
      at org.apache.batik.gvt.CompositeGraphicsNode.primitivePaint(CompositeGraphicsNode.java:165)
      at org.apache.batik.gvt.AbstractGraphicsNode.paint(AbstractGraphicsNode.java:509)
      at org.apache.batik.gvt.CompositeGraphicsNode.primitivePaint(CompositeGraphicsNode.java:165)
      at org.apache.batik.gvt.AbstractGraphicsNode.paint(AbstractGraphicsNode.java:509)
      at org.apache.batik.gvt.CompositeGraphicsNode.primitivePaint(CompositeGraphicsNode.java:165)
      at org.apache.batik.gvt.CanvasGraphicsNode.primitivePaint(CanvasGraphicsNode.java:159)
      at org.apache.batik.gvt.AbstractGraphicsNode.paint(AbstractGraphicsNode.java:509)
      at org.apache.batik.gvt.CompositeGraphicsNode.primitivePaint(CompositeGraphicsNode.java:165)
      at org.apache.batik.gvt.AbstractGraphicsNode.paint(AbstractGraphicsNode.java:509)
      at org.apache.batik.gvt.renderer.MacRenderer.repaint(MacRenderer.java:361)
      at org.apache.batik.gvt.renderer.MacRenderer.repaint(MacRenderer.java:291)
      at org.apache.batik.transcoder.image.ImageTranscoder.transcode(ImageTranscoder.java:111)
      at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(XMLAbstractTranscoder.java:142)
      at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:156)
      at com.dji.converter.epub.constructor.ImageConstructor.convertVectorImage(ImageConstructor.java:305)
      at com.dji.converter.epub.constructor.ImageConstructor.createImage(ImageConstructor.java:109)
      at com.dji.converter.epub.constructor.ImageConstructor.handleStartEvent(ImageConstructor.java:80)
      at com.dji.converter.epub.ePubConverter.processEvents(ePubConverter.java:334)
      at com.dji.converter.epub.ePubConverter.convert(ePubConverter.java:202)
      at com.dji.converter.ConverterBase.run(ConverterBase.java:91)
      at java.lang.Thread.run(Thread.java:613)
      Invalid memory access of location 0x128 eip=0x4dcd8a

      The code in question is pretty straightforward, but one odd thing did happen: I never hit the catch(Exception e) clause, which I should have done for an NPE:

      try {
      String parser = XMLResourceDescriptor.getXMLParserClassName();
      SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
      String svgURI = imageSourcePath.toURL().toString();
      Document doc = f.createDocument(svgURI);

      // Get the root element (the 'svg' element).
      final Element svgRoot = doc.getDocumentElement();

      // Set the width and height attributes on the root 'svg' element.
      final String strWidth = svgRoot.getAttributeNS(null, "width");
      if (strWidth != null)

      { actualWidth = Float.parseFloat(strWidth); }

      final String strHeight = svgRoot.getAttributeNS(null, "height");
      if (strHeight != null)

      { actualHeight = Float.parseFloat(strHeight); }

      if ((actualWidth != Float.MAX_VALUE) && (actualWidth > maxImageWidth))

      { float proportion = maxImageWidth / actualWidth; actualWidth = proportion * actualWidth; actualHeight = proportion * actualHeight; }

      if ((actualHeight != Float.MAX_VALUE) && (actualHeight > maxImageHeight))

      { float proportion = maxImageHeight / actualHeight; actualWidth = proportion * actualWidth; actualHeight = proportion * actualHeight; }

      // Create a JPEG transcoder
      ImageTranscoder t = null;
      if (imageOutputFormat.equalsIgnoreCase("jpeg"))

      { t = new JPEGTranscoder(); }

      else if (imageOutputFormat.equalsIgnoreCase("png"))

      { t = new PNGTranscoder(); }

      else

      { throw new UnsupportedImageFormatException("Cannot convert SVG to " + imageOutputFormat); }

      // Set the transcoding hints.
      t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(.8));
      t.addTranscodingHint(JPEGTranscoder.KEY_WIDTH, actualWidth);
      t.addTranscodingHint(JPEGTranscoder.KEY_HEIGHT, actualHeight);

      // Create the transcoder input.
      TranscoderInput input = new TranscoderInput(doc);

      // Create the transcoder output.
      OutputStream ostream = new FileOutputStream(imageDestPath);
      TranscoderOutput output = new TranscoderOutput(ostream);

      // Save the image.
      t.transcode(input, output);

      // Flush and close the stream.
      ostream.flush();
      ostream.close();

      finalImagePath = imageDestPath;
      } catch (FileNotFoundException e)

      { logger.error("Image file not found", e); getStatusAccumulator().addWarningMessage("The image file " + imageSourcePath + " specified in the XML was not found."); finalImagePath = imageSourcePath; }

      catch (IOException e)

      { logger.error("Image I/O error", e); getStatusAccumulator().addWarningMessage("An error occurred while processing image file " + imageSourcePath + ": " + e.getMessage()); finalImagePath = imageSourcePath; }

      catch (TranscoderException e)

      { logger.error("Image conversion error", e); getStatusAccumulator().addWarningMessage("An error occurred while processing image file " + imageSourcePath + ": " + e.getMessage()); finalImagePath = imageSourcePath; }

      catch (Exception e)

      { // Batik sometimes NPEs... logger.error("Image conversion error", e); getStatusAccumulator().addWarningMessage("An error occurred while processing image file " + imageSourcePath + ": " + e.getMessage()); finalImagePath = imageSourcePath; }

      Thanks in advance for any help you can provide.

      Cheers
      Chris

        Attachments

          Activity

            People

            • Assignee:
              batik-dev@xmlgraphics.apache.org Batik Developer's Mailing list
              Reporter:
              chris@techadapt.com chris
            • Votes:
              2 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: