question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exceptions reading some SVG files and Batik

See original GitHub issue

First of all, I’m really happy with this 3.4.1 release, thank you for a great job! All the problems that I’ve encountered had been solved, except with some SVG files.

Now, there is a very high chance that this is not a TwelveMonkey’s problem, I bet it is an issue within Batik (and I do know that Batik does not support everything) or I’m doing something wrong (like missing some jar files), but I felt it was worth mentioning.

The problem happens only with some SVG images, like the one at the wikipedia page “SVG exported from KOMPAS-Graphic”.

When I try to read this file, I get this:

2018-09-17 09:49:50 FINE: null
Enclosed Exception:
The current document is unable to create an element of the requested type (namespace: http://www.w3.org/2000/svg, name: drawing-type). [@meew.FileManager getCurrentImage]
javax.imageio.IIOException: null
Enclosed Exception:
The current document is unable to create an element of the requested type (namespace: http://www.w3.org/2000/svg, name: drawing-type).
	at com.twelvemonkeys.imageio.plugins.svg.SVGImageReader.getWidth(SVGImageReader.java:232)
	at com.twelvemonkeys.imageio.plugins.svg.SVGImageReader.read(SVGImageReader.java:131)
	at javax.imageio.ImageReader.read(ImageReader.java:939)
	at meew.FileManager.getCurrentImage(FileManager.java:2046)
	...
Caused by: org.apache.batik.transcoder.TranscoderException: null
Enclosed Exception:
The current document is unable to create an element of the requested type (namespace: http://www.w3.org/2000/svg, name: drawing-type).
	at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(XMLAbstractTranscoder.java:134)
	at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:156)
	at com.twelvemonkeys.imageio.plugins.svg.SVGImageReader$Rasterizer.init(SVGImageReader.java:549)
	at com.twelvemonkeys.imageio.plugins.svg.SVGImageReader$Rasterizer.getDefaultWidth(SVGImageReader.java:562)
	at com.twelvemonkeys.imageio.plugins.svg.SVGImageReader.getWidth(SVGImageReader.java:229)
	... 40 more
Caused by: org.w3c.dom.DOMException: The current document is unable to create an element of the requested type (namespace: http://www.w3.org/2000/svg, name: drawing-type).
	at org.apache.batik.dom.AbstractNode.createDOMException(AbstractNode.java:407)
	at org.apache.batik.anim.dom.SVGDOMImplementation.createElementNS(SVGDOMImplementation.java:202)
	at org.apache.batik.anim.dom.SVGOMDocument.createElementNS(SVGOMDocument.java:373)
	at org.apache.batik.dom.util.SAXDocumentFactory.startElement(SAXDocumentFactory.java:651)
	at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
	at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
	at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
	at org.apache.batik.dom.util.SAXDocumentFactory.createDocument(SAXDocumentFactory.java:453)
	at org.apache.batik.dom.util.SAXDocumentFactory.createDocument(SAXDocumentFactory.java:357)
	at org.apache.batik.anim.dom.SAXSVGDocumentFactory.createDocument(SAXSVGDocumentFactory.java:225)
	at org.apache.batik.anim.dom.SAXSVGDocumentFactory.createDocument(SAXSVGDocumentFactory.java:300)
	at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(XMLAbstractTranscoder.java:114)
	... 44 more

I can’t find any info about this drawing-type tag. I edited the xml of the file to remove that tag to test it. The image is displayed exactly the same in Firefox, with or without the tag. When I try to load the image removing the <drawing-type>1</drawing-type>, the exception changes to:


java.lang.NullPointerException
	at org.apache.batik.css.engine.CSSEngine.parseStyleSheet(CSSEngine.java:1223)
	at org.apache.batik.css.engine.CSSEngine.parseStyleSheet(CSSEngine.java:1204)
	at org.apache.batik.anim.dom.SVGOMStyleElement.getCSSStyleSheet(SVGOMStyleElement.java:140)
	at org.apache.batik.css.engine.CSSEngine.getStyleSheetNodes(CSSEngine.java:923)
	at org.apache.batik.css.engine.CSSEngine.getCascadedStyleMap(CSSEngine.java:785)
	at org.apache.batik.css.engine.CSSEngine.getComputedStyle(CSSEngine.java:867)
	at org.apache.batik.bridge.CSSUtilities.getComputedStyle(CSSUtilities.java:81)
	at org.apache.batik.bridge.CSSUtilities.convertVisibility(CSSUtilities.java:578)
	at org.apache.batik.bridge.SVGSVGElementBridge.createGraphicsNode(SVGSVGElementBridge.java:141)
	at org.apache.batik.bridge.GVTBuilder.build(GVTBuilder.java:76)
	at com.twelvemonkeys.imageio.plugins.svg.SVGImageReader$Rasterizer.transcode(SVGImageReader.java:309)
	at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(XMLAbstractTranscoder.java:142)
	at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:156)
	at com.twelvemonkeys.imageio.plugins.svg.SVGImageReader$Rasterizer.init(SVGImageReader.java:549)
	at com.twelvemonkeys.imageio.plugins.svg.SVGImageReader$Rasterizer.getDefaultWidth(SVGImageReader.java:562)
	at com.twelvemonkeys.imageio.plugins.svg.SVGImageReader.getWidth(SVGImageReader.java:229)
	at com.twelvemonkeys.imageio.plugins.svg.SVGImageReader.read(SVGImageReader.java:131)
	at javax.imageio.ImageReader.read(ImageReader.java:939)
	at meew.FileManager.getCurrentImage(FileManager.java:2046)
	...

Do you know anything about this? This also happened in the previous 3.3.2 version. I’m using Batik version 1.10 now but the problem happened in the 1.9 version as well. By the way, I saw in the TwelveMonkey’s release notes that “Batik dependencies updated to 1.9”, so is it safe if I use 1.10?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:23 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
j-p-sequeiracommented, Oct 19, 2018

Not yet, but I will!! I promise to come back with the results soon.

0reactions
haraldkcommented, Oct 19, 2018

I can’t see anything in the spec about them having to be on a specific line… But you need to report that bug to the Batik guys, as I don’t control the parsing.

As I mentioned above, I think a better approach (than re-serializing to a byte array) would be to just pass the pre-parsed document to the reader. Did you try that out yet?

– Harald K

Read more comments on GitHub >

github_iconTop Results From Across the Web

Batik URL exception in Windows - java - Stack Overflow
It's supposed to read all SVG files within a directory and to show the images I'm using Batik along with this transcoder class...
Read more >
Jasper + Batik SVG file - strange exception
I'm building some application at with genetare a transfer forms etc. Right now I have a transfer form as a svg file.
Read more >
Frequently Asked Questions - Apache XML Graphics Project
Batik is a Java-based toolkit for applications or applets that want to use images in the Scalable Vector Graphics (SVG) format for various...
Read more >
Vulnerabilities in Apache Batik Default Security Controls
It immediately caught my attention, as this library parses Scalable Vector Graphics (SVG) files and transforms them into different raster ...
Read more >
SVG User Experiences - Apache OpenOffice Wiki
130) over Fedora Core 2, but I get an "unknown format error" while I've successfully installed the svg-import-r2009 package. Is it because the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found