JAL-3659 proper headless check; skips setProperty for JS
authorBobHanson <hansonr@stolaf.edu>
Tue, 16 Jun 2020 23:09:57 +0000 (18:09 -0500)
committerBobHanson <hansonr@stolaf.edu>
Tue, 16 Jun 2020 23:09:57 +0000 (18:09 -0500)
src/jalview/bin/Jalview.java

index 4522167..fea99fb 100755 (executable)
@@ -20,6 +20,7 @@
  */
 package jalview.bin;
 
+import java.awt.GraphicsEnvironment;
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileOutputStream;
@@ -327,15 +328,19 @@ public class Jalview implements ApplicationSingletonI
         showUsage();
         System.exit(0);
       }
-      // ?>>
+      // BH note: Only -nodisplay is official; others are deprecated?
       if (aparser.contains("nodisplay") || aparser.contains("nogui")
-              || aparser.contains("headless"))
+              || aparser.contains("headless")
+              || GraphicsEnvironment.isHeadless())
       {
-        // BH Is this necessary? Seems like a hack; was removed for applet branch 
-        System.setProperty("java.awt.headless", "true");
+        if (!isJS) {
+          // BH Definitely not a good idea in JavaScript; 
+          // probably should not be here for Java, either.  
+          System.setProperty("java.awt.headless", "true");
+        }
         headless = true;
       }
-      if ("true".equals(System.getProperty("java.awt.headless")))
+      if (GraphicsEnvironment.isHeadless())
       {
         headless = true;
       }