leifeld / dna

Discourse Network Analyzer (DNA)
126 stars 41 forks source link

Error in dna_init() : java.awt.HeadlessException #270

Closed fchavesco closed 8 months ago

fchavesco commented 1 year ago

I am trying to run dna_init() and the system throws java.awt.HeadlessException. I have java version 17. I've tried using both rDNA 3.0.10 and 3.0.9. I have a Mac (macOs Ventura 13.2.1).

system("java -version") openjdk version "17.0.6" 2023-01-17 OpenJDK Runtime Environment Temurin-17.0.6+10 (build 17.0.6+10) OpenJDK 64-Bit Server VM Temurin-17.0.6+10 (build 17.0.6+10, mixed mode)

leifeld commented 1 year ago

Thanks for reporting this. I'll look into it in the next weeks.

I think it may be a MacOS issue and should also happen in server environments without graphical capabilities (i.e., a remote server shell). The reason might be that Java AWT components like the java.awt.color class are used in the code accessed by R.

If you require an immediate solution, you can try running it on a non-Mac computer or in RStudio Cloud.

fchavesco commented 1 year ago

Thanks for the help! I've tried to run it on RStudio cloud and received this problem:

dna_init() Jar file found in library path. Jar file: /cloud/lib/x86_64-pc-linux-gnu-library/4.2/rDNA/inst/java/dna-3.0.9.jar Error in dna_init() : java.lang.NoClassDefFoundError: Could not initialize class java.awt.GraphicsEnvironment$LocalGE

leifeld commented 1 year ago

This indicates that rDNA has an old jar file version lying around in the library path. It's attempting to use that one instead of the one you have in your working directory. Make sure you use the current 3.0.10 version of both DNA and rDNA and, if necessary, delete the 3.0.9 jar file from the path indicated in the error message. It could be caused by a prior installation of rDNA 3.0.9, for example.

leifeld commented 1 year ago

If you are sure that you have rDNA 3.0.10 installed and deleting the file does not help, you can also set the relative or absolute path of the jar file you intend to use as an argument in your dna_init call.

leifeld commented 8 months ago

This issue was fixed in commit 1906b0cffe338f6ea95fb7aa6d63f0db2f318c5a and will be part of the next DNA release 3.0.11.

The problem was that rDNA called the Exporter Java class in DNA, which in turn relied on the java.awt.Color class like many other parts of DNA to save colours of coders, statements, regexes etc. The Color class, however, depends on the graphics output system X11 to work. On some systems, such as HPC servers, X11 is not available. In such cases, rDNA throws a java.awt.HeadlessException. Headless means there is no X11 graphics system although the code calls for it (via the Color class as mentioned above).

For some reason, when you install the rJava R package on MacOS, it throws a warning about not being able to load the X11 libraries for compiling rJava. It's not preventing users from installing rJava, but apparently any code that requires X11 doesn't work in that case, so the result is the same as on a server without X11, such as a Linux server. As rDNA depends in rJava, this effectively led rDNA to throw the java.awt.HeadlessException on MacOS as well.

In the commit, I replaced all those instances of java.awt.Color throughout DNA with a new, rewritten Color class. I wrote this as a light-weight container that simply contains RGB values and can be converted to a java.awt.Color object when needed. With this replacement, it works on MacOS as well as Linux servers now; I have tested it on both.

nfk1215 commented 6 months ago

How can I implement this commit to fix the bug that occurs in the dna_init() step? When can we expect the 3.0.11 release?