From: hansonr Date: Tue, 14 May 2019 21:47:14 +0000 (-0500) Subject: Fix to not create lasting static instance in JavaScript; trims up code X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=5864fb13da0d1c50f0b16be014e73394ec234f46;p=jalview.git Fix to not create lasting static instance in JavaScript; trims up code --- diff --git a/src/jalview/bin/Instance.java b/src/jalview/bin/Instance.java index 3bcd618..a8db18f 100644 --- a/src/jalview/bin/Instance.java +++ b/src/jalview/bin/Instance.java @@ -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; }