Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kandy toPNG reports NullPointerException #1228

Closed
gmitch215 opened this issue Oct 25, 2024 · 4 comments
Closed

Kandy toPNG reports NullPointerException #1228

gmitch215 opened this issue Oct 25, 2024 · 4 comments
Labels
Milestone

Comments

@gmitch215
Copy link

gmitch215 commented Oct 25, 2024

Hello,

I'm using Kandy for creating graphing data using Kotlin. Occasionally, the toPNG function throws this error:

[DefaultDispatcher-worker-5] ERROR SpecTransformBackendUtil - Internal error: NullPointerException : <no message>
java.lang.NullPointerException
        at org.jetbrains.letsPlot.core.plot.base.GeomMeta.renders(GeomMeta.kt:24)
        at org.jetbrains.letsPlot.core.plot.base.GeomMeta.renders(GeomMeta.kt:33)
        at org.jetbrains.letsPlot.core.plot.base.GeomMeta.renders$default(GeomMeta.kt:27)
        at org.jetbrains.letsPlot.core.spec.config.LayerConfig.<init>(LayerConfig.kt:74)
        at org.jetbrains.letsPlot.core.spec.config.PlotConfig.createLayerConfig(PlotConfig.kt:160)
        at org.jetbrains.letsPlot.core.spec.config.PlotConfig.createLayerConfigs(PlotConfig.kt:133)
        at org.jetbrains.letsPlot.core.spec.config.PlotConfig.<init>(PlotConfig.kt:80)
        at org.jetbrains.letsPlot.core.spec.back.PlotConfigBackend.<init>(PlotConfigBackend.kt:40)
        at org.jetbrains.letsPlot.core.spec.back.SpecTransformBackendUtil.processTransformIntern2(SpecTransformBackendUtil.kt:154)
        at org.jetbrains.letsPlot.core.spec.back.SpecTransformBackendUtil.processTransformIntern(SpecTransformBackendUtil.kt:136)
        at org.jetbrains.letsPlot.core.spec.back.SpecTransformBackendUtil.processTransform$plot_stem(SpecTransformBackendUtil.kt:42)
        at org.jetbrains.letsPlot.core.spec.back.SpecTransformBackendUtil.processTransform(SpecTransformBackendUtil.kt:22)
        at org.jetbrains.letsPlot.core.util.MonolithicCommon.processRawSpecs(MonolithicCommon.kt:326)
        at org.jetbrains.letsPlot.core.util.MonolithicCommon.buildSvgImagesFromRawSpecs(MonolithicCommon.kt:37)
        at org.jetbrains.letsPlot.core.util.PlotSvgExportCommon.buildSvgImageFromRawSpecs(PlotSvgExportCommon.kt:35)
        at org.jetbrains.letsPlot.awt.plot.PlotSvgExport.buildSvgImageFromRawSpecs(PlotSvgExport.kt:24)
        at org.jetbrains.letsPlot.awt.plot.PlotSvgExport.buildSvgImageFromRawSpecs$default(PlotSvgExport.kt:19)
        at org.jetbrains.letsPlot.core.plot.export.PlotImageExport.buildImageFromRawSpecs(PlotImageExport.kt:90)
        at org.jetbrains.kotlinx.kandy.letsplot.export.ToBufferedImageKt.toBufferedImage(toBufferedImage.kt:28)
        at org.jetbrains.kotlinx.kandy.letsplot.export.ToBufferedImageKt.toPNG(toBufferedImage.kt:99)
        at org.jetbrains.kotlinx.kandy.letsplot.export.ToBufferedImageKt.toPNG$default(toBufferedImage.kt:95)

It seems to be directly a Lets-Plot bug instead of a Kandy bug, and is linked to this line of code in GeomMeta:

@ThreadLocal
object GeomMeta {
    private val renderedAesByGeom = HashMap<GeomKind, List<Aes<*>>>()

    private fun renders(geomKind: GeomKind): List<Aes<*>> {
        if (!renderedAesByGeom.containsKey(geomKind)) {
            renderedAesByGeom[geomKind] =
                renderedAesList(geomKind)
        }
        return renderedAesByGeom[geomKind]!! // thrown here
    }
@alshan
Copy link
Collaborator

alshan commented Oct 30, 2024

Hi, in what environment did you get this error? I.e., Jupyter notebook/lab, Kotlin notebook plugin in IntelliJ IDEA, or other?

@gmitch215
Copy link
Author

Using Kandy as a gradle dependency on Kotlin/JVM.

dependencies {
    // ...
    implementation("org.jetbrains.kotlinx:kandy-lets-plot:0.7.1")

@alshan
Copy link
Collaborator

alshan commented Oct 30, 2024

Uh-oh, apparently @ThreadLocal only has an effect on the Kotlin/Native platform.

I understand you are calling toPNG() in your own mulithreded app?

@gmitch215
Copy link
Author

Yes, I'm using coroutines on the JVM.

@alshan alshan added this to the 2024Q4 milestone Nov 1, 2024
@alshan alshan added the * label Nov 1, 2024
@alshan alshan closed this as completed in 6d95b8b Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants