From: Jim Procter Date: Mon, 12 Aug 2019 15:43:57 +0000 (+0100) Subject: JAL-3235 isolated the 'unsafe' override of entrySet to the saveProperties method... X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fbug%2FJAL-3235sortPropertiesJava9-2;p=jalview.git JAL-3235 isolated the 'unsafe' override of entrySet to the saveProperties method, since we only need ordered output on save --- diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index 2bafb10..f40fc61 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -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 keys() - { - return Collections.enumeration(new TreeSet<>(super.keySet())); - } - - // override so properties are output in alphabetical order (Java 11) - @Override - public Set> entrySet() - { - Map 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 keys() + { + return Collections.enumeration(new TreeSet<>(super.keySet())); + } + + // override so properties are output in alphabetical order (Java 11) + @Override + public Set> entrySet() + { + Map 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) {