I figured out when it happens but not why. PlantUML (a diagramming java tool) is run with a wrapper script that respects the JAVA_HOME environment variable.
If I install openjdk as a staged package within the snap and set the JAVA_HOME environment variable to point to openjdk within the snap, plantuml fails about 50% (87 out of 200 runs) with an error like:
WARNING: failed to run plantuml: java.io.IOException: Stream closed
(The stream it is trying to write to is an image file somewhere in the user’s home directory.)
If I remove openjdk as a staged package and instead let PlantUML find the JAVA_HOME in my normal, non-snap environment, it never fails. In other words, in this scenario, PlantUML uses the same version of java, just a version installed outside the snap and works fine.
I have used openjdk in other Java game snaps w/o issue.