Kotlin / kandy

Kotlin plotting library.
https://kotlin.github.io/kandy/
Apache License 2.0
535 stars 11 forks source link

Exception when saving a plot with `.png` extension #232

Closed nicolasfara closed 1 month ago

nicolasfara commented 8 months ago

Describe the bug

When trying to plot the example proposed in: https://github.com/Kotlin/kandy/blob/main/examples/idea-examples/lets-plot-simple/src/main/kotlin/org/jetbrains/kotlinx/kandy/letsplot/simple_lets_plot.kt

I got the following exception:

org.xml.sax.SAXNotRecognizedException: unrecognized feature http://xml.org/sax/features/external-general-entities
    at org.gjt.xpp.sax2.Driver.setFeature(Driver.java:178)
    at org.gjt.xpp.jaxp11.SAXParserImpl.setFeatures(SAXParserImpl.java:149)
    at org.gjt.xpp.jaxp11.SAXParserImpl.<init>(SAXParserImpl.java:132)
    at org.gjt.xpp.jaxp11.SAXParserFactoryImpl.newSAXParserImpl(SAXParserFactoryImpl.java:114)
    at org.gjt.xpp.jaxp11.SAXParserFactoryImpl.setFeature(SAXParserFactoryImpl.java:142)
    at org.apache.batik.dom.util.SAXDocumentFactory.<clinit>(SAXDocumentFactory.java:403)
    at org.apache.batik.transcoder.SVGAbstractTranscoder.createDocumentFactory(SVGAbstractTranscoder.java:152)
    at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(XMLAbstractTranscoder.java:108)
    at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:158)
    at jetbrains.datalore.plot.PlotImageExport.buildImageFromRawSpecs(PlotImageExport.kt:117)
    at org.jetbrains.letsPlot.export.GgsaveKt.exportRasterImage(ggsave.kt:123)
    at org.jetbrains.letsPlot.export.GgsaveKt.ggsave(ggsave.kt:88)
    at org.jetbrains.kotlinx.kandy.letsplot.export.SaveKt.save(save.kt:38)
    at org.jetbrains.kotlinx.kandy.letsplot.export.SaveKt.save$default(save.kt:33)
    at it.unibo.pulverization.ChartsKt.main(Charts.kt:137)
    at it.unibo.pulverization.ChartsKt.main(Charts.kt)
Exception in thread "main" org.apache.batik.transcoder.TranscoderException: null
Enclosed Exception:
unrecognized feature http://xml.org/sax/features/external-general-entities
    at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(XMLAbstractTranscoder.java:136)
    at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:158)
    at jetbrains.datalore.plot.PlotImageExport.buildImageFromRawSpecs(PlotImageExport.kt:117)
    at org.jetbrains.letsPlot.export.GgsaveKt.exportRasterImage(ggsave.kt:123)
    at org.jetbrains.letsPlot.export.GgsaveKt.ggsave(ggsave.kt:88)
    at org.jetbrains.kotlinx.kandy.letsplot.export.SaveKt.save(save.kt:38)
    at org.jetbrains.kotlinx.kandy.letsplot.export.SaveKt.save$default(save.kt:33)
    at it.unibo.pulverization.ChartsKt.main(Charts.kt:137)
    at it.unibo.pulverization.ChartsKt.main(Charts.kt)
Caused by: org.apache.batik.dom.util.SAXIOException: unrecognized feature http://xml.org/sax/features/external-general-entities
    at org.apache.batik.dom.util.SAXDocumentFactory.createDocument(SAXDocumentFactory.java:459)
    at org.apache.batik.dom.util.SAXDocumentFactory.createDocument(SAXDocumentFactory.java:357)
    at org.apache.batik.anim.dom.SAXSVGDocumentFactory.createDocument(SAXSVGDocumentFactory.java:255)
    at org.apache.batik.anim.dom.SAXSVGDocumentFactory.createDocument(SAXSVGDocumentFactory.java:317)
    at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(XMLAbstractTranscoder.java:119)
    ... 8 more
Caused by: org.xml.sax.SAXNotRecognizedException: unrecognized feature http://xml.org/sax/features/external-general-entities
    at org.gjt.xpp.sax2.Driver.setFeature(Driver.java:178)
    at org.apache.batik.dom.util.SAXDocumentFactory.createDocument(SAXDocumentFactory.java:448)
    ... 12 more

To Reproduce

Steps to reproduce the behavior:

  1. Execute the code provided in the example

Expected behavior

Save the figure as an .png without exception

Actual Behavior

The aforementioned exception is raised

Library Version, Tool version, and Environment

(please complete the following information):

Additional information

I use the library directly in IntelliJ, not in a notebook

AndreiKingsley commented 8 months ago

Hi, we couldn't reproduce this bug. Could you please specify the Kotlin version and your OS? Lets-plot uses the Batik library to save plots to PNG, which is platform dependent. You can also try to use an actual dev version (0.4.5-dev-31).

devcrocod commented 1 month ago

This bug doesn't reproduce on the latest versions of the library (since 0.5)