Fix to not create lasting static instance in JavaScript; trims up code
authorhansonr <hansonr@STO24954W.ad.stolaf.edu>
Tue, 14 May 2019 21:47:14 +0000 (16:47 -0500)
committerhansonr <hansonr@STO24954W.ad.stolaf.edu>
Tue, 14 May 2019 21:47:14 +0000 (16:47 -0500)
src/jalview/bin/Instance.java

index 3bcd618..a8db18f 100644 (file)
@@ -38,6 +38,7 @@ import jalview.schemes.ColourSchemes;
 import jalview.structure.StructureImportSettings;
 import jalview.structure.StructureSelectionManager;
 import jalview.urls.IdOrgSettings;
+import jalview.util.Platform;
 import jalview.ws.jws1.Discoverer;
 import jalview.ws.jws2.Jws2Discoverer;
 import jalview.ws.jws2.jabaws2.Jws2InstanceFactory;
@@ -86,21 +87,23 @@ public class Instance
    */
   public static Instance getInstance()
   {
-    Instance i;
+
+    // assign g only if JavaScript and instance only if Java
+
     @SuppressWarnings("unused")
-    ThreadGroup g = Thread.currentThread().getThreadGroup();
-    /**
-     * @j2sNative i = g._jalviewInstance;
-     */
-    {
-      i = instance;
-    }
+    ThreadGroup g = (Platform.isJS()
+            ? Thread.currentThread().getThreadGroup()
+            : null);
+    Instance i = /** @j2sNative g._jalviewInstance || */
+            instance;
     if (i == null)
     {
-      i = instance = new Instance();
-      /**
-       * @j2sNative g._jalviewInstance = i;
-       */
+      i = /**
+           * @j2sNative g._jalviewInstance =
+           */
+              new Instance();
+      instance = /** @j2sNative null && */
+              i;
     }
     return i;
   }