fix #8939: fix getIntValue for preference with no db and no local preference
authorKatja Luther <k.luther@bgbm.org>
Mon, 6 Apr 2020 08:14:26 +0000 (10:14 +0200)
committerKatja Luther <k.luther@bgbm.org>
Mon, 6 Apr 2020 08:14:26 +0000 (10:14 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java

index 6397436d02adb1a10696de2de55e5f64253d7934..cd7a8faa4688b4e9d629db0ef789f8bf39df99d7 100644 (file)
@@ -337,18 +337,7 @@ public class PreferencesUtil implements IPreferenceKeys {
             result = Integer.parseInt(prefValue);
         }catch(NumberFormatException e){
             logger.debug("Preference value of " + name + " is not a number");
-            if (prefValue == null){
-                if (pref != null){
-                    String predicate = pref.getPredicate();
-                    IPreferencePredicate pred = PreferencePredicate.getByKey(predicate);
-                    Object defaultValue = pred.getDefaultValue();
-                    if (defaultValue instanceof String){
-                        result = Integer.valueOf((String)defaultValue);
-                    } else if (defaultValue instanceof Integer){
-                        result = (Integer)defaultValue;
-                    }
-                }
-            }
+
         }
         String overrideKey =  createPreferenceString(createOverridePreferenceString(name));
         boolean override = getPreferenceStore().getBoolean(overrideKey);
@@ -356,19 +345,27 @@ public class PreferencesUtil implements IPreferenceKeys {
             String dbSpecific = prefKey(name);
             if (getPreferenceStore().contains(dbSpecific)){
                 result = getPreferenceStore().getInt(dbSpecific);
-            }else{
-                if (result == null){
-                    IPreferencePredicate pred = PreferencePredicate.getByKey(name);
-                    if (pred != null){
-                        if (pred.getDefaultValue() instanceof Integer){
-                            return (Integer)pred.getDefaultValue();
-                        }else if (pred.getDefaultValue() != null){
-                            return Integer.valueOf(pred.getDefaultValue().toString());
-                        }
+            }
+        }
+        if (result == null){
+            IPreferencePredicate pred = PreferencePredicate.getByKey(name);
+            if (pred != null){
+                if (pred.getDefaultValue() instanceof Integer){
+                    result = (Integer)pred.getDefaultValue();
+                }else if (pred.getDefaultValue() != null){
+                    try{
+                        result = Integer.valueOf(pred.getDefaultValue().toString());
+                    }catch(NumberFormatException e){
+                        logger.debug("Preference value of " + name + " is not a number");
+                        result = 0;
                     }
-                    return 0;
                 }
             }
+            //if no default value available
+            if (result == null){
+                result = 0;
+            }
+
         }
         return result;