Why does this 4-line .puml file cause a java delay for more than a minute before exiting?

0 votes
asked Nov 28, 2021 in Bug by pmorch (120 points)
edited Nov 28, 2021 by pmorch

Hi,

I've followed "Calling PlantUML from Java" https://plantuml.com/api and that exact example works fine.

However, when I use it to render any C4 .puml file, for some reason, java hangs for about a minute after generation before exiting the java process. In fact, main() is done almost immediately. If I hit "pause" in Intellij, I can see that java is "hanging" in:

    java.lang.ref.Reference#waitForReferencePendingList

which has this signature:

    private static native void waitForReferencePendingList();

I've narrowed it down to any .puml file that !include-s a https:// file. (For that, I've created a github gist file containing only a one-line comment)

If main() ends with a System.exit(0), it finishes without the 1 min delay, but I shouldn't have to put System.exit(0) in main() - that is usually implied.

Any ideas on how I can get java to avoid waiting one minute in waitForReferencePendingList? I've tried to look at net.sourceforge.plantuml.Run#main, but there are many other things going on and no clues jumped out at me.

Here is a complete reproducible example, with only minor differences from the API example: The addition of the !includeurl and the println().

        String source = "@startuml\n";
        source += "!includeurl https://gist.githubusercontent.com/pmorch/acc087c40df50c1877d328c0f0afcdfe/raw/3d8109a3725110ee4762506034404c8ad5029aae/emptyfile.puml\n";
        source += "Bob -> Alice : hello\n";
        source += "@enduml\n";

        SourceStringReader reader = new SourceStringReader(source);
        final ByteArrayOutputStream os = new ByteArrayOutputStream();
        // Write the first image to "os"
        String desc = reader.generateImage(os, new FileFormatOption(FileFormat.SVG));
        os.close();

        // The XML is stored into svg
        final String svg = new String(os.toByteArray(), Charset.forName("UTF-8"));
        System.out.println("Done " + new Date());
        // System.exit(0);

I've tried multiple PlantUML versions, at least:

net.sourceforge.plantuml:plantuml:1.2021.14
and
net.sourceforge.plantuml:plantuml:1.2021.1

1 Answer

0 votes
answered Nov 28, 2021 by plantuml (294,960 points)

Many thanks for the feedback.

I think the answer is here.

There is an Executors.newCachedThreadPool() in SURL.java

We are going to fix it.

commented Nov 28, 2021 by plantuml (294,960 points)
This may be fixed in last snapshot https://github.com/plantuml/plantuml/releases/tag/snapshot

Tell us if it's not working for you.

Thanks!
commented Nov 29, 2021 by pmorch (120 points)
Thanks, I can confirm that https://github.com/plantuml/plantuml/releases/tag/snapshot fixes it.
...