From 6430749d46cda00bb591268ef3ade3386b927c73 Mon Sep 17 00:00:00 2001 From: Steve Rowe Date: Tue, 28 Aug 2018 12:42:59 -0400 Subject: [PATCH] SOLR-12662: Reproducing TestPolicy failures: NPE and NoClassDefFoundError --- solr/CHANGES.txt | 3 +++ .../solrj/cloud/autoscaling/VariableBase.java | 16 ++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 5733ce5eb13..520e9151b5c 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -8146,6 +8146,9 @@ Bug Fixes * SOLR-6693: bin\solr.cmd doesn't support 32-bit JRE/JDK running on Windows due to parenthesis in JAVA_HOME. (Timothy Potter, Christopher Hewitt, Jan Høydahl) + +* SOLR-12662: Reproducing TestPolicy failures: NPE and NoClassDefFoundError. + (Steve Rowe) Optimizations ---------------------- diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/VariableBase.java b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/VariableBase.java index 4387eb10713..8b0c1cf52ea 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/VariableBase.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/cloud/autoscaling/VariableBase.java @@ -77,7 +77,7 @@ public class VariableBase implements Variable { } public static Type getTagType(String name) { - Type info = validatetypes.get(name); + Type info = getValidatetypes().get(name); if (info == null && name.startsWith(ImplicitSnitch.SYSPROP)) info = Type.STRING; if (info == null && name.startsWith(Clause.METRICS_PREFIX)) info = Type.LAZY; return info; @@ -196,11 +196,15 @@ public class VariableBase implements Variable { } - private static Map validatetypes; + private static Map validatetypes = null; - static { - validatetypes = new HashMap<>(); - for (Type t : Type.values()) - validatetypes.put(t.tagName, t); + /** SOLR-12662: Lazily init validatetypes to avoid Type.values() NPE due to static initializer ordering */ + private static Map getValidatetypes() { + if (validatetypes == null) { + validatetypes = new HashMap<>(); + for (Type t : Type.values()) + validatetypes.put(t.tagName, t); + } + return validatetypes; } }