Could not initialize class net.sourceforge.plantuml.ugraphic.UFont

0 votes
asked Jun 18, 2020 in Question / help by anonymous
edited Jun 18, 2020

Hi,

When we tried to use the plantuml lib to generate call flow diagrams, we've got the following exception.

java.lang.NoClassDefFoundError: Could not initialize class net.sourceforge.plantuml.ugraphic.UFont
at net.sourceforge.plantuml.graphic.GraphicStrings.sansSerif12(GraphicStrings.java:119)
at net.sourceforge.plantuml.graphic.GraphicStrings.createBlackOnWhite(GraphicStrings.java:114)
at net.sourceforge.plantuml.UmlDiagram.exportDiagramError(UmlDiagram.java:246)
at net.sourceforge.plantuml.UmlDiagram.exportDiagramError(UmlDiagram.java:219)
at net.sourceforge.plantuml.UmlDiagram.exportDiagramNow(UmlDiagram.java:212)
at net.sourceforge.plantuml.AbstractPSystem.exportDiagram(AbstractPSystem.java:140)
at net.sourceforge.plantuml.SourceStringReader.outputImage(SourceStringReader.java:156)
at net.sourceforge.plantuml.SourceStringReader.outputImage(SourceStringReader.java:128)

Our environment is: plantuml 1.2020.12, tomcat 7.0.94,  and openJDK 1.8.0_252-b09 in virtual linux.

Any solution to solve this issue? Thanks.

Hong

commented Jun 19, 2020 by Serge Wenger Work (15,620 points)
Please provide a small example to help reproduce
commented Jun 24, 2020 by anonymous
something like:

String text = "@startuml\n" +

"Alice -> Bob: Authentication Request\n" +

"Bob --> Alice: Authentication Response\n" +

"@enduml";

    private URI generateCallflowDiagram(String text, String outputFile) {

        try {

            logger.info("generateCallflowDiagram: " + text + " outputFile=: " + outputFile);

            SourceStringReader reader = new SourceStringReader(text);

            logger.info("sourcestringreader made");

            final ByteArrayOutputStream os = new ByteArrayOutputStream();

            logger.info("bytearrayoutputstream created");

            String desc = reader.outputImage(os, new FileFormatOption(FileFormat.SVG)).getDescription();

            logger.info("image generated");

            os.close();

....
commented Aug 4, 2020 by anonymous
I would also like an answer to this
commented Aug 10, 2020 by Serge Wenger Work (15,620 points)
Sorry. I was on holidays and I have not the same environnement. Is it working in a file with the command line?
commented Aug 20, 2020 by anonymous
Hi, to update this issue, I downloaded the docker Tomcat image that the production server runs out of and added a jar containing just the code shown in the above comment. The Jar was extracted with dependancies (only plantuml) using maven from a java project that included the plantuml library as a dependancy through maven pom file. When I enter the tomcat image through a bash entry point and execute the jar, I get the same error that was initially described, I have posted a fuller version below. I was under the impression that the plantuml libraries don't need any additional libraries or dependancies for sequence diagrams like the example from my code and that it should run with 100% Java. The tomcat image has several different versions of Java, and all of them experienced the same error. Are there any additional libraries or packages that need to be installed at the os level to make this work? I see x11 library in this error message, but didn't think you needed to do anything with that for sequence diagrams. Let me know if I should still add the plantuml jar to the docker image and run that from commandline.

java.lang.ExceptionInInitializerError

    at net.sourceforge.plantuml.SkinParam.getFont(SkinParam.java:485)

    at net.sourceforge.plantuml.SkinParamDelegator.getFont(SkinParamDelegator.java:83)

    at net.sourceforge.plantuml.skin.rose.Rose.createComponent(Rose.java:95)

    at net.sourceforge.plantuml.sequencediagram.graphic.DrawableSetInitializer.prepareParticipant(DrawableSetInitializer.java:626)

    at net.sourceforge.plantuml.sequencediagram.graphic.DrawableSetInitializer.createDrawableSet(DrawableSetInitializer.java:140)

    at net.sourceforge.plantuml.sequencediagram.graphic.SequenceDiagramFileMakerPuma2.<init>(SequenceDiagramFileMakerPuma2.java:116)

    at net.sourceforge.plantuml.sequencediagram.SequenceDiagram.getSequenceDiagramPngMaker(SequenceDiagram.java:241)

    at net.sourceforge.plantuml.sequencediagram.SequenceDiagram.getNbImages(SequenceDiagram.java:419)

    at net.sourceforge.plantuml.SourceStringReader.outputImage(SourceStringReader.java:153)

    at net.sourceforge.plantuml.SourceStringReader.outputImage(SourceStringReader.java:128)

    at Main.main(Main.java:22)

Caused by: java.lang.NullPointerException

    at sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1264)

    at sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:219)

    at sun.awt.FontConfiguration.init(FontConfiguration.java:107)

    at sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:774)

    at sun.font.SunFontManager$2.run(SunFontManager.java:431)

    at java.security.AccessController.doPrivileged(Native Method)

    at sun.font.SunFontManager.<init>(SunFontManager.java:376)

    at sun.awt.FcFontManager.<init>(FcFontManager.java:35)

    at sun.awt.X11FontManager.<init>(X11FontManager.java:57)

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)

    at java.lang.Class.newInstance(Class.java:442)

    at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:83)

    at java.security.AccessController.doPrivileged(Native Method)

    at sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)

    at sun.java2d.SunGraphicsEnvironment.getFontManagerForSGE(SunGraphicsEnvironment.java:190)

    at sun.java2d.SunGraphicsEnvironment.getAvailableFontFamilyNames(SunGraphicsEnvironment.java:224)

    at sun.java2d.SunGraphicsEnvironment.getAvailableFontFamilyNames(SunGraphicsEnvironment.java:252)

    at sun.java2d.HeadlessGraphicsEnvironment.getAvailableFontFamilyNames(HeadlessGraphicsEnvironment.java:94)

    at net.sourceforge.plantuml.ugraphic.UFont.<clinit>(UFont.java:60)

    ... 11 more

java.lang.NoClassDefFoundError: Could not initialize class net.sourceforge.plantuml.ugraphic.UFont

    at net.sourceforge.plantuml.SkinParam.getFont(SkinParam.java:485)

    at net.sourceforge.plantuml.SkinParamDelegator.getFont(SkinParamDelegator.java:83)

    at net.sourceforge.plantuml.skin.rose.Rose.createComponent(Rose.java:95)

    at net.sourceforge.plantuml.sequencediagram.graphic.DrawableSetInitializer.prepareParticipant(DrawableSetInitializer.java:626)

    at net.sourceforge.plantuml.sequencediagram.graphic.DrawableSetInitializer.createDrawableSet(DrawableSetInitializer.java:140)

    at net.sourceforge.plantuml.sequencediagram.graphic.SequenceDiagramFileMakerPuma2.<init>(SequenceDiagramFileMakerPuma2.java:116)

    at net.sourceforge.plantuml.sequencediagram.SequenceDiagram.getSequenceDiagramPngMaker(SequenceDiagram.java:241)

    at net.sourceforge.plantuml.sequencediagram.SequenceDiagram.exportDiagramInternal(SequenceDiagram.java:251)

    at net.sourceforge.plantuml.UmlDiagram.exportDiagramNow(UmlDiagram.java:201)

    at net.sourceforge.plantuml.AbstractPSystem.exportDiagram(AbstractPSystem.java:140)

    at net.sourceforge.plantuml.SourceStringReader.outputImage(SourceStringReader.java:156)

    at net.sourceforge.plantuml.SourceStringReader.outputImage(SourceStringReader.java:128)

    at Main.main(Main.java:22)

Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class net.sourceforge.plantuml.ugraphic.UFont

    at net.sourceforge.plantuml.graphic.GraphicStrings.sansSerif12(GraphicStrings.java:119)

    at net.sourceforge.plantuml.graphic.GraphicStrings.createBlackOnWhite(GraphicStrings.java:114)

    at net.sourceforge.plantuml.UmlDiagram.exportDiagramError(UmlDiagram.java:246)

    at net.sourceforge.plantuml.UmlDiagram.exportDiagramError(UmlDiagram.java:219)

    at net.sourceforge.plantuml.UmlDiagram.exportDiagramNow(UmlDiagram.java:212)

    at net.sourceforge.plantuml.AbstractPSystem.exportDiagram(AbstractPSystem.java:140)

    at net.sourceforge.plantuml.SourceStringReader.outputImage(SourceStringReader.java:156)

    at net.sourceforge.plantuml.SourceStringReader.outputImage(SourceStringReader.java:128)

    at Main.main(Main.java:22)
commented Oct 30, 2020 by Gunjan
Same issue with all later plantuml version (2020.x)
commented May 26, 2021 by dizzy
Is there any solution to this? I am experiencing the exact same issue on Apache Tomcat 8.5.42, JVM 12.0.1+12. I have tried both the pre-packed .war files and with manual packaging using maven - no difference.

For some reason the classes cannot be reached, that's clear. Plantuml team?
commented May 26, 2021 by plantuml (294,960 points)

If you have some messages like: 

Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class net.sourceforge.plantuml.ugraphic.UFont

it could mean that you don't have graphical environment on your server.

See https://plantuml.com/en/faq#239d64f675c3e515

Can you try to run the command line to see if it works here.

commented Jun 14, 2021 by dizzy
Hi,

No option to access the cmd line on the host server. Possible to build this flag into the pom.xml?

Please advise.

1 Answer

0 votes
answered Mar 24, 2021 by rnz

Same bug on AdoptOpenJDK under SunOS 11.3 sun4v sparc:

# java -version
openjdk version "1.8.0_282"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_282-b08)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.282-b08, mixed mode)

commented Jun 14, 2021 by anonymous
hi i am original poster of this question. we solved it by adding fontconfig to the list of things apt-get install on the docker image
...