JAL-3235 isolated the 'unsafe' override of entrySet to the saveProperties method... bug/JAL-3235sortPropertiesJava9-2
authorJim Procter <jprocter@issues.jalview.org>
Mon, 12 Aug 2019 15:43:57 +0000 (16:43 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Mon, 12 Aug 2019 15:43:57 +0000 (16:43 +0100)
src/jalview/bin/Cache.java

index 2bafb10..f40fc61 100755 (executable)
@@ -268,27 +268,7 @@ public class Cache
   public static Logger log;
 
   /** Jalview Properties */
-  public static Properties applicationProperties = new Properties()
-  {
-    // override so properties are output in alphabetical order (Java 8)
-    @Override
-    public synchronized Enumeration<Object> keys()
-    {
-      return Collections.enumeration(new TreeSet<>(super.keySet()));
-    }
-
-    // override so properties are output in alphabetical order (Java 11)
-    @Override
-    public Set<Entry<Object, Object>> entrySet()
-    {
-      Map<Object, Object> copy = new TreeMap<>();
-      for (Object key : this.keySet())
-      {
-        copy.put(key, this.get(key));
-      }
-      return copy.entrySet();
-    }
-  };
+  public static Properties applicationProperties = new Properties();
 
   /** Default file is ~/.jalview_properties */
   static String propertiesFile;
@@ -690,8 +670,31 @@ public class Cache
     {
       try
       {
+        Properties orderedProperties = new Properties()
+        {
+          // override so properties are output in alphabetical order (Java 8)
+          @Override
+          public synchronized Enumeration<Object> keys()
+          {
+            return Collections.enumeration(new TreeSet<>(super.keySet()));
+          }
+
+          // override so properties are output in alphabetical order (Java 11)
+          @Override
+          public Set<Entry<Object, Object>> entrySet()
+          {
+            Map<Object, Object> copy = new TreeMap<>();
+            for (Object key : this.keySet())
+            {
+              copy.put(key, this.get(key));
+            }
+            return copy.entrySet();
+          }
+        };
+        orderedProperties.putAll(applicationProperties);
+
         FileOutputStream out = new FileOutputStream(propertiesFile);
-        applicationProperties.store(out, "---JalviewX Properties File---");
+        orderedProperties.store(out, "---JalviewX Properties File---");
         out.close();
       } catch (Exception ex)
       {