From cb4ccb3c548b45c2c4d09c5c34281dc2e4d5923f Mon Sep 17 00:00:00 2001 From: gmungoc Date: Tue, 16 Jan 2018 12:19:24 +0000 Subject: [PATCH] JAL-1270 JAL-2885 clear properties before load --- src/jalview/bin/Cache.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index dc50843..dcd6546 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -281,7 +281,7 @@ public class Cache @Override public synchronized Enumeration keys() { - return Collections.enumeration(new TreeSet(super.keySet())); + return Collections.enumeration(new TreeSet<>(super.keySet())); } }; @@ -334,7 +334,10 @@ public class Cache } } - /** Called when Jalview is started */ + /** + * Loads properties from the given properties file. Any existing properties + * are first cleared. + */ public static void loadProperties(String propsFile) { propertiesFile = propsFile; @@ -369,6 +372,7 @@ public class Cache { fis = new FileInputStream(propertiesFile); } + applicationProperties.clear(); applicationProperties.load(fis); // remove any old build properties @@ -621,14 +625,14 @@ public class Cache * @param obj * String value of property * - * @return String value of property + * @return previous value of property (or null) */ - public static String setProperty(String key, String obj) + public static Object setProperty(String key, String obj) { - + Object oldValue = null; try { - applicationProperties.setProperty(key, obj); + oldValue = applicationProperties.setProperty(key, obj); if (!propsAreReadOnly) { FileOutputStream out = new FileOutputStream(propertiesFile); @@ -640,7 +644,7 @@ public class Cache System.out.println( "Error setting property: " + key + " " + obj + "\n" + ex); } - return obj; + return oldValue; } /** -- 1.7.10.2