Apache Lucene open-source search software
formatting fixed
Noble Paul5c6d796fca3e
diff --git a/solr/core/src/java/org/apache/solr/core/InitParams.java b/solr/core/src/java/org/apache/solr/core/InitParams.javaindex 424b98ad3fd..b390eb54b9e 100644--- a/solr/core/src/java/org/apache/solr/core/InitParams.java+++ b/solr/core/src/java/org/apache/solr/core/InitParams.java@@ -33,49 +33,49 @@ public class InitParams {public static final String TYPE = "initParams";public final String name;public final Set<String> paths;- public final NamedList defaults,invariants,appends;+ public final NamedList defaults, invariants, appends;public InitParams(PluginInfo p) {this.name = p.attributes.get("name");Set<String> paths = null;String pathStr = p.attributes.get("path");- if(pathStr!=null) {+ if (pathStr != null) {paths = Collections.unmodifiableSet(new HashSet<>(StrUtils.splitSmart(pathStr, ',')));}this.paths = paths;NamedList nl = (NamedList) p.initArgs.get(PluginInfo.DEFAULTS);- defaults = nl == null ? null: nl.getImmutableCopy();+ defaults = nl == null ? null : nl.getImmutableCopy();nl = (NamedList) p.initArgs.get(PluginInfo.INVARIANTS);- invariants = nl == null ? null: nl.getImmutableCopy();+ invariants = nl == null ? null : nl.getImmutableCopy();nl = (NamedList) p.initArgs.get(PluginInfo.APPENDS);- appends = nl == null ? null: nl.getImmutableCopy();+ appends = nl == null ? null : nl.getImmutableCopy();}public boolean matchPath(String name) {- if(paths == null) return false;- if(paths.contains(name)) return true;+ if (paths == null) return false;+ if (paths.contains(name)) return true;for (String path : paths) {- if(matchPath(path,name)) return true;+ if (matchPath(path, name)) return true;}return false;}- private static boolean matchPath(String path, String name){+ private static boolean matchPath(String path, String name) {List<String> pathSplit = StrUtils.splitSmart(path, '/');List<String> nameSplit = StrUtils.splitSmart(name, '/');int i = 0;- for (;i < nameSplit.size(); i++) {+ for (; i < nameSplit.size(); i++) {String s = nameSplit.get(i);- String ps = pathSplit.size()>i ? pathSplit.get(i) :null;- if(ps == null) return false;- if(s.equals(ps)) continue;- if("*".equals(ps) && nameSplit.size()==i+1) return true;- if("**".equals(ps)) return true;+ String ps = pathSplit.size() > i ? pathSplit.get(i) : null;+ if (ps == null) return false;+ if (s.equals(ps)) continue;+ if ("*".equals(ps) && nameSplit.size() == i + 1) return true;+ if ("**".equals(ps)) return true;return false;}- String ps = pathSplit.size()>i ? pathSplit.get(i) :null;+ String ps = pathSplit.size() > i ? pathSplit.get(i) : null;return "*".equals(ps) || "**".equals(ps);}@@ -83,29 +83,29 @@ public class InitParams {public void apply(PluginInfo info) {if (!info.isFromSolrConfig()) {//if this is a component implicitly defined in code it should be overridden by initPrams- merge(defaults, (NamedList) info.initArgs.get(PluginInfo.DEFAULTS) ,info.initArgs, PluginInfo.DEFAULTS, false);+ merge(defaults, (NamedList) info.initArgs.get(PluginInfo.DEFAULTS), info.initArgs, PluginInfo.DEFAULTS, false);} else {//if the args is initialized from solrconfig.xml inside the requesthHandler it should be taking precedence over initParams- merge( (NamedList) info.initArgs.get(PluginInfo.DEFAULTS), defaults,info.initArgs, PluginInfo.DEFAULTS, false);+ merge((NamedList) info.initArgs.get(PluginInfo.DEFAULTS), defaults, info.initArgs, PluginInfo.DEFAULTS, false);}merge((NamedList) info.initArgs.get(PluginInfo.INVARIANTS), invariants, info.initArgs, PluginInfo.INVARIANTS, false);merge((NamedList) info.initArgs.get(PluginInfo.APPENDS), appends, info.initArgs, PluginInfo.APPENDS, true);}- private static void merge(NamedList first, NamedList second, NamedList sink, String name, boolean appends) {- if(first == null && second == null) return;- if(first == null) first = new NamedList();+ private static void merge(NamedList first, NamedList second, NamedList sink, String name, boolean appends) {+ if (first == null && second == null) return;+ if (first == null) first = new NamedList();NamedList nl = first.clone();- if(appends) {- if(second!=null) nl.addAll(second);+ if (appends) {+ if (second != null) nl.addAll(second);} else {Set<String> a = new HashSet<>();Set<String> b = new HashSet<>();- for (Object o : first) {- Map.Entry<String,Object> e = (Map.Entry) o;- a.add(e.getKey() );+ for (Object o : first) {+ Map.Entry<String, Object> e = (Map.Entry) o;+ a.add(e.getKey());}- if(second!=null) {+ if (second != null) {for (Object o : second) {Map.Entry<String, Object> e = (Map.Entry) o;b.add(e.getKey());@@ -116,10 +116,10 @@ public class InitParams {for (Object v : second.getAll(s)) nl.add(s, v);}}- if(sink.indexOf(name,0) >-1) {+ if (sink.indexOf(name, 0) > -1) {sink.setVal(sink.indexOf(name, 0), nl);} else {- sink.add(name,nl);+ sink.add(name, nl);}}}diff --git a/solr/core/src/java/org/apache/solr/core/JarRepository.java b/solr/core/src/java/org/apache/solr/core/JarRepository.javaindex 25ba7c01d53..cfb4893a5b9 100644--- a/solr/core/src/java/org/apache/solr/core/JarRepository.java+++ b/solr/core/src/java/org/apache/solr/core/JarRepository.java@@ -51,8 +51,8 @@ import org.slf4j.LoggerFactory;*/public class JarRepository {public static Logger log = LoggerFactory.getLogger(JarRepository.class);-static final Random RANDOM;+static {// We try to make things reproducible in the context of our tests by initializing the random instance// based on the current seed@@ -63,20 +63,18 @@ public class JarRepository {RANDOM = new Random(seed.hashCode());}}-+private final CoreContainer coreContainer;-- private Map<String,JarContent> jars = new ConcurrentHashMap<>();-+ private Map<String, JarContent> jars = new ConcurrentHashMap<>();+public JarRepository(CoreContainer coreContainer) {this.coreContainer = coreContainer;}-+/*** Returns the contents of a jar and increments a reference count. Please return the same object to decerease the refcount- *- * @param key- * it is a combination of blobname and version like blobName/version+ *+ * @param key it is a combination of blobname and version like blobName/version* @return The reference of a jar*/public JarContentRef getJarIncRef(String key) throws IOException {@@ -89,11 +87,12 @@ public class JarRepository {ArrayList<Slice> slices = new ArrayList<>(coll.getActiveSlices());if (slices.isEmpty()) throw new SolrException(SERVICE_UNAVAILABLE, ".no active slices for .system collection");Collections.shuffle(slices, RANDOM); //do load balancing- Slice slice = slices.get(0) ;+ Slice slice = slices.get(0);Replica replica = slice.getReplicas().iterator().next();- if (replica == null) throw new SolrException(SERVICE_UNAVAILABLE, ".no active replica available for .system collection");+ if (replica == null)+ throw new SolrException(SERVICE_UNAVAILABLE, ".no active replica available for .system collection");String url = replica.getStr(BASE_URL_PROP) + "/.system/blob/" + key + "?wt=filestream";-+HttpClient httpClient = coreContainer.getUpdateShardHandler().getHttpClient();HttpGet httpGet = new HttpGet(url);ByteBuffer b;@@ -109,27 +108,26 @@ public class JarRepository {}jars.put(key, jar = new JarContent(key, b));} else {-+throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Jar loading is not supported in non-cloud mode");// todo-+}-+}-+JarContentRef ref = new JarContentRef(jar);synchronized (jar.references) {jar.references.add(ref);}return ref;-+}-+/*** This is to decrement a ref count- *- * @param ref- * The reference that is already there. Doing multiple calls with same ref will not matter+ *+ * @param ref The reference that is already there. Doing multiple calls with same ref will not matter*/public void decrementJarRefCount(JarContentRef ref) {if (ref == null) return;@@ -141,21 +139,21 @@ public class JarRepository {jars.remove(ref.jar.key);}}-+}-+public static class JarContent {private final String key;// TODO move this off-heapprivate final ByteBuffer buffer;// ref counting mechanismprivate final Set<JarContentRef> references = new HashSet<>();-+public JarContent(String key, ByteBuffer buffer) {this.key = key;this.buffer = buffer;}-+public ByteBuffer getFileContent(String entryName) throws IOException {ByteArrayInputStream zipContents = new ByteArrayInputStream(buffer.array(), buffer.arrayOffset(), buffer.limit());ZipInputStream zis = new ZipInputStream(zipContents);@@ -178,15 +176,15 @@ public class JarRepository {}return null;}-+}-+public static class JarContentRef {public final JarContent jar;-+private JarContentRef(JarContent jar) {this.jar = jar;}}-+}diff --git a/solr/core/src/java/org/apache/solr/core/RequestParams.java b/solr/core/src/java/org/apache/solr/core/RequestParams.javaindex a1050be35eb..17f4123f841 100644--- a/solr/core/src/java/org/apache/solr/core/RequestParams.java+++ b/solr/core/src/java/org/apache/solr/core/RequestParams.java@@ -39,29 +39,29 @@ import org.noggit.ObjectBuilder;import org.slf4j.Logger;import org.slf4j.LoggerFactory;-/**The class encapsulates the request time parameters . This is immutable and any changes performed+/**+ * The class encapsulates the request time parameters . This is immutable and any changes performed* returns a copy of the Object with the changed values- **/-public class RequestParams implements MapSerializable{+public class RequestParams implements MapSerializable {public static final Logger log = LoggerFactory.getLogger(RequestParams.class);private final Map data;- private final Map<String , VersionedParams> paramsets = new LinkedHashMap<>();- private final int znodeVersion ;+ private final Map<String, VersionedParams> paramsets = new LinkedHashMap<>();+ private final int znodeVersion;public RequestParams(Map data, int znodeVersion) {- if(data == null) data = Collections.EMPTY_MAP;+ if (data == null) data = Collections.EMPTY_MAP;this.data = data;Map paramsets = (Map) data.get(NAME);- if(paramsets != null) {+ if (paramsets != null) {for (Object o : paramsets.entrySet()) {Map.Entry e = (Map.Entry) o;if (e.getValue() instanceof Map) {Map value = (Map) e.getValue();Map copy = getMapCopy(value);Map meta = (Map) copy.remove("");- this.paramsets.put((String) e.getKey(), new VersionedParams(Collections.unmodifiableMap(copy) ,meta));+ this.paramsets.put((String) e.getKey(), new VersionedParams(Collections.unmodifiableMap(copy), meta));}}}@@ -72,8 +72,8 @@ public class RequestParams implements MapSerializable{Map copy = new LinkedHashMap<>();for (Object o1 : value.entrySet()) {Map.Entry entry = (Map.Entry) o1;- if("".equals( entry.getKey())){- copy.put(entry.getKey(),entry.getValue());+ if ("".equals(entry.getKey())) {+ copy.put(entry.getKey(), entry.getValue());continue;}if (entry.getValue() != null) {@@ -81,7 +81,7 @@ public class RequestParams implements MapSerializable{List l = (List) entry.getValue();String[] sarr = new String[l.size()];for (int i = 0; i < l.size(); i++) {- if( l.get(i) != null) sarr[i]= String.valueOf(l.get(i));+ if (l.get(i) != null) sarr[i] = String.valueOf(l.get(i));}copy.put(entry.getKey(), sarr);} else {@@ -94,11 +94,11 @@ public class RequestParams implements MapSerializable{return copy;}- public VersionedParams getParams(String name){+ public VersionedParams getParams(String name) {return paramsets.get(name);}- public int getZnodeVersion(){+ public int getZnodeVersion() {return znodeVersion;}@@ -114,46 +114,46 @@ public class RequestParams implements MapSerializable{return result;}- public RequestParams setParams(String name , Map values){+ public RequestParams setParams(String name, Map values) {Map deepCopy = getDeepCopy(data, 3);Map p = (Map) deepCopy.get(NAME);- if(p == null) deepCopy.put(NAME, p= new LinkedHashMap());- if(values == null){+ if (p == null) deepCopy.put(NAME, p = new LinkedHashMap());+ if (values == null) {p.remove(name);} else {Map old = (Map) p.get(name);long version = 0;Map meta = null;- if(old != null){+ if (old != null) {meta = (Map) old.get("");- if(meta!=null) {+ if (meta != null) {Long oldVersion = (Long) old.get("v");- if(oldVersion != null) version = oldVersion.longValue()+1;+ if (oldVersion != null) version = oldVersion.longValue() + 1;}meta = new LinkedHashMap<>(meta);} else {meta = new LinkedHashMap<>();}- meta.put("v",version);+ meta.put("v", version);values = new LinkedHashMap<>(values);- values.put("",meta);- p.put(name,values);+ values.put("", meta);+ p.put(name, values);}return new RequestParams(deepCopy, znodeVersion);}- public static RequestParams getFreshRequestParams(SolrResourceLoader loader, RequestParams requestParams){+ public static RequestParams getFreshRequestParams(SolrResourceLoader loader, RequestParams requestParams) {if (loader instanceof ZkSolrResourceLoader) {ZkSolrResourceLoader resourceLoader = (ZkSolrResourceLoader) loader;try {- Stat stat = resourceLoader.getZkController().getZkClient().exists(resourceLoader.getConfigSetZkPath()+"/"+ RequestParams.RESOURCE,null,true);- if(stat == null) {- requestParams = new RequestParams(Collections.EMPTY_MAP,-1);- } else if(requestParams == null || stat.getVersion() > requestParams.getZnodeVersion()) {+ Stat stat = resourceLoader.getZkController().getZkClient().exists(resourceLoader.getConfigSetZkPath() + "/" + RequestParams.RESOURCE, null, true);+ if (stat == null) {+ requestParams = new RequestParams(Collections.EMPTY_MAP, -1);+ } else if (requestParams == null || stat.getVersion() > requestParams.getZnodeVersion()) {Object[] o = getMapAndVersion(loader, RequestParams.RESOURCE);- requestParams = new RequestParams((Map) o[0],(Integer)o[1]);- log.info("request params refreshed to version {}",requestParams.getZnodeVersion());+ requestParams = new RequestParams((Map) o[0], (Integer) o[1]);+ log.info("request params refreshed to version {}", requestParams.getZnodeVersion());}} catch (KeeperException e) {throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);@@ -162,7 +162,7 @@ public class RequestParams implements MapSerializable{throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);}- } else {+ } else {Object[] o = getMapAndVersion(loader, RequestParams.RESOURCE);requestParams = new RequestParams((Map) o[0], (Integer) o[1]);}@@ -172,7 +172,7 @@ public class RequestParams implements MapSerializable{}- private static Object[] getMapAndVersion(SolrResourceLoader loader, String name) {+ private static Object[] getMapAndVersion(SolrResourceLoader loader, String name) {InputStream in = null;try {in = loader.openResource(name);@@ -181,31 +181,31 @@ public class RequestParams implements MapSerializable{return new Object[]{Collections.EMPTY_MAP, -1};}- int version = 0; //will be always 0 for file based resourceloader- if (in instanceof ZkSolrResourceLoader.ZkByteArrayInputStream) {- version = ((ZkSolrResourceLoader.ZkByteArrayInputStream) in).getStat().getVersion();- log.info( "conf resource {} loaded . version : {} ", name,version);- }+ int version = 0; //will be always 0 for file based resourceloader+ if (in instanceof ZkSolrResourceLoader.ZkByteArrayInputStream) {+ version = ((ZkSolrResourceLoader.ZkByteArrayInputStream) in).getStat().getVersion();+ log.info("conf resource {} loaded . version : {} ", name, version);+ }try {Map m = (Map) ObjectBuilder.getVal(new JSONParser(new InputStreamReader(in, StandardCharsets.UTF_8)));- return new Object[]{m,version};+ return new Object[]{m, version};} catch (IOException e) {- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,"Error parsing conf resource "+name,e);+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Error parsing conf resource " + name, e);}}- public static Map getDeepCopy(Map map, int maxDepth){+ public static Map getDeepCopy(Map map, int maxDepth) {Map copy = new LinkedHashMap<>();for (Object o : map.entrySet()) {Map.Entry e = (Map.Entry) o;Object v = e.getValue();if (v instanceof Map && maxDepth > 0) {- v = getDeepCopy ( (Map) v, maxDepth -1);+ v = getDeepCopy((Map) v, maxDepth - 1);}- copy.put(e.getKey(),v);+ copy.put(e.getKey(), v);}return copy;}@@ -213,24 +213,26 @@ public class RequestParams implements MapSerializable{public byte[] toByteArray() {return ZkStateReader.toJSON(data);}+public static final String USEPARAM = "useParams";public static final String NAME = "params";public static final String RESOURCE = "params.json";- public static class VersionedParams extends MapSolrParams{+ public static class VersionedParams extends MapSolrParams {Map meta;public VersionedParams(Map<String, String> map, Map meta) {super(map);this.meta = meta;}- public Map getRawMap(){++ public Map getRawMap() {return meta;}public Long getVersion() {- return meta == null? 0l : (Long)meta.get("v");+ return meta == null ? 0l : (Long) meta.get("v");}}}diff --git a/solr/solrj/src/java/org/apache/solr/common/util/JsonRecordReader.java b/solr/solrj/src/java/org/apache/solr/common/util/JsonRecordReader.javaindex 81bf221106f..c3afde74149 100644--- a/solr/solrj/src/java/org/apache/solr/common/util/JsonRecordReader.java+++ b/solr/solrj/src/java/org/apache/solr/common/util/JsonRecordReader.java@@ -25,13 +25,14 @@ import org.noggit.JSONParser;import static org.noggit.JSONParser.*;-/**A Streaming parser for json to emit one record at a time.+/**+ * A Streaming parser for json to emit one record at a time.*/public class JsonRecordReader {public static final String DELIM = ".";- private Node rootNode = new Node("/", (Node)null);+ private Node rootNode = new Node("/", (Node) null);public static JsonRecordReader getInst(String split, List<String> fieldMappings) {@@ -40,7 +41,7 @@ public class JsonRecordReader {String path = s;int idx = s.indexOf(':');String fieldName = null;- if(idx >0) {+ if (idx > 0) {fieldName = s.substring(0, idx);path = s.substring(idx + 1);}@@ -61,7 +62,7 @@ public class JsonRecordReader {* emitted the collected fields are cleared. Any fields collected in the* parent tag or above will also be included in the record, but these are* not cleared after emitting the record.- * <p/>+ * <p>* It uses the ' | ' syntax of PATH to pass in multiple paths.*/private JsonRecordReader(String splitPath) {@@ -82,17 +83,17 @@ public class JsonRecordReader {* construct a tree of Nodes representing path segments. The resulting* tree structure ends up describing all the paths we are interested in.*- * @param path The path expression for this field- * @param fieldName The name for this field in the emitted record+ * @param path The path expression for this field+ * @param fieldName The name for this field in the emitted record* @param multiValued If 'true' then the emitted record will have values in* a List<String>* @param isRecord Flags that this PATH is from a forEach statement*/private void addField(String path, String fieldName, boolean multiValued, boolean isRecord) {- if(!path.startsWith("/")) throw new RuntimeException("All paths must start with '/' "+ path);+ if (!path.startsWith("/")) throw new RuntimeException("All paths must start with '/' " + path);List<String> paths = splitEscapeQuote(path);- if(paths.size() ==0) {- if(isRecord) rootNode.isRecord=true;+ if (paths.size() == 0) {+ if (isRecord) rootNode.isRecord = true;return;//the patrh is "/"}// deal with how split behaves when seperator starts a string!@@ -154,11 +155,11 @@ public class JsonRecordReader {String name; // generally: segment of the path represented by this NodeString fieldName; // the fieldname in the emitted record (key of the map)String splitPath; // the full path from the forEach entity attribute- final LinkedHashMap<String ,Node> childNodes = new LinkedHashMap<>(); // List of immediate child Nodes of this node+ final LinkedHashMap<String, Node> childNodes = new LinkedHashMap<>(); // List of immediate child Nodes of this nodeNode parent; // parent Node in the treeboolean isLeaf = false; // flag: store/emit streamed text for this nodeboolean isRecord = false; //flag: this Node starts a new record- Node wildCardChild ;+ Node wildCardChild;Node recursiveWildCardChild;private boolean useFqn = false;@@ -182,7 +183,7 @@ public class JsonRecordReader {* child nodes.*/private void buildOptimize() {- if(parent != null && parent.recursiveWildCardChild !=null && this.recursiveWildCardChild ==null){+ if (parent != null && parent.recursiveWildCardChild != null && this.recursiveWildCardChild == null) {this.recursiveWildCardChild = parent.recursiveWildCardChild;}for (Node n : childNodes.values()) n.buildOptimize();@@ -207,7 +208,7 @@ public class JsonRecordReader {// recursively walk the paths Lists adding new Nodes as requiredString segment = paths.remove(0); // shift out next path segment- if(segment.length() < 1) throw new RuntimeException("all pieces in path must be non empty "+path);+ if (segment.length() < 1) throw new RuntimeException("all pieces in path must be non empty " + path);// does this "name" already exist as a child node.Node n = getOrAddNode(segment, childNodes);@@ -228,29 +229,30 @@ public class JsonRecordReader {if (n.name.equals(WILDCARD_PATH)) {wildCardChild = n;}- if (n.name.equals(RECURSIVE_WILDCARD_PATH) ) {- recursiveWildCardChild = n.recursiveWildCardChild= n;+ if (n.name.equals(RECURSIVE_WILDCARD_PATH)) {+ recursiveWildCardChild = n.recursiveWildCardChild = n;}// path with content we want to store and returnn.isLeaf = true; // we have to store text found heren.fieldName = fieldName; // name to store collected text against- if("$FQN".equals(n.fieldName)) {+ if ("$FQN".equals(n.fieldName)) {n.fieldName = null;n.useFqn = true;}}} else {//wildcards must only come at the end- if(WILDCARD_PATH.equals(name) || RECURSIVE_WILDCARD_PATH.equals(name)) throw new RuntimeException("wild cards are allowed only in the end "+path) ;+ if (WILDCARD_PATH.equals(name) || RECURSIVE_WILDCARD_PATH.equals(name))+ throw new RuntimeException("wild cards are allowed only in the end " + path);// recurse to handle next paths segmentn.build(paths, fieldName, multiValued, record, path);}}- private Node getOrAddNode(String pathName, Map<String,Node> children) {+ private Node getOrAddNode(String pathName, Map<String, Node> children) {Node n = children.get(pathName);- if(n !=null) return n;+ if (n != null) return n;// new territory! add a new node for this path bittychildren.put(pathName, n = new Node(pathName, this));return n;@@ -282,7 +284,7 @@ public class JsonRecordReader {int event = -1;for (; ; ) {event = parser.nextEvent();- if(event == EOF) break;+ if (event == EOF) break;if (event == OBJECT_START) {handleObjectStart(parser, new HashSet<Node>(), handler, values, stack, recordStarted, null);} else if (event == ARRAY_START) {@@ -290,7 +292,7 @@ public class JsonRecordReader {event = parser.nextEvent();if (event == ARRAY_END) break;if (event == OBJECT_START) {- handleObjectStart(parser, new HashSet<Node>(), handler, values, stack, recordStarted,null);+ handleObjectStart(parser, new HashSet<Node>(), handler, values, stack, recordStarted, null);}}}@@ -304,7 +306,7 @@ public class JsonRecordReader {* tree then walk back though the tree's ancestor nodes checking to see if* any // expressions exist for the node and compare them against the new* tag. If matched then "jump" to that node, otherwise ignore the tag.- * <p/>+ * <p>* Note, the list of // expressions found while walking back up the tree* is chached in the HashMap decends. Then if the new tag is to be skipped,* any inner chil tags are compared against the cache and jumped to if@@ -333,7 +335,7 @@ public class JsonRecordReader {class Wrapper extends MethodFrameWrapper {Wrapper(Node node, MethodFrameWrapper parent, String name) {this.node = node;- this.parent= parent;+ this.parent = parent;this.name = name;}@@ -346,7 +348,7 @@ public class JsonRecordReader {event = parser.nextEvent();if (event == ARRAY_END) break;if (event == OBJECT_START) {- node.handleObjectStart(parser, childrenFound, handler, values, stack, isRecordStarted,this);+ node.handleObjectStart(parser, childrenFound, handler, values, stack, isRecordStarted, this);}}}@@ -368,19 +370,19 @@ public class JsonRecordReader {String name = parser.getString();Node node = childNodes.get(name);- if(node == null) node = wildCardChild;- if(node == null) node = recursiveWildCardChild;+ if (node == null) node = wildCardChild;+ if (node == null) node = recursiveWildCardChild;if (node != null) {if (node.isLeaf) {//this is a leaf collect data hereevent = parser.nextEvent();String nameInRecord = node.fieldName == null ? getNameInRecord(name, frameWrapper, node) : node.fieldName;MethodFrameWrapper runnable = null;- if(event == OBJECT_START || event == ARRAY_START){- if(node.recursiveWildCardChild !=null) runnable = new Wrapper(node, frameWrapper,name);+ if (event == OBJECT_START || event == ARRAY_START) {+ if (node.recursiveWildCardChild != null) runnable = new Wrapper(node, frameWrapper, name);}Object val = parseSingleFieldValue(event, parser, runnable);- if(val !=null) {+ if (val != null) {putValue(values, nameInRecord, val);if (isRecordStarted) valuesAddedinThisFrame.add(nameInRecord);}@@ -423,8 +425,8 @@ public class JsonRecordReader {}}- private String getNameInRecord(String name,MethodFrameWrapper frameWrapper, Node n) {- if(frameWrapper == null || !n.useFqn) return name;+ private String getNameInRecord(String name, MethodFrameWrapper frameWrapper, Node n) {+ if (frameWrapper == null || !n.useFqn) return name;StringBuilder sb = new StringBuilder();frameWrapper.prependName(sb);return sb.append(DELIM).append(name).toString();@@ -436,7 +438,7 @@ public class JsonRecordReader {private void putValue(Map<String, Object> values, String fieldName, Object o) {- if(o==null) return;+ if (o == null) return;Object val = values.get(fieldName);if (val == null) {values.put(fieldName, o);@@ -466,7 +468,7 @@ public class JsonRecordReader {* this method deals with special cases where there is a slash '/' character* inside the attribute value e.g. x/@html='text/html'. We split by '/' but* then reassemble things were the '/' appears within a quoted sub-string.- * <p/>+ * <p>* We have already enforced that the string must begin with a seperator. This* method depends heavily on how split behaves if the string starts with the* seperator or if a sequence of multiple seperator's appear.@@ -501,7 +503,7 @@ public class JsonRecordReader {* @param record The record map. The key is the field name as provided in* the addField() methods. The value can be a single String (for single* valued fields) or a List<String> (for multiValued).- * @param path The forEach path for which this record is being emitted+ * @param path The forEach path for which this record is being emitted* If there is any change all parsing will be aborted and the Exception* is propagated up*/@@ -524,25 +526,26 @@ public class JsonRecordReader {parser.getNull();return null;case ARRAY_START:- return parseArrayFieldValue(ev, parser,runnable);- case OBJECT_START:- if(runnable !=null) {+ return parseArrayFieldValue(ev, parser, runnable);+ case OBJECT_START:+ if (runnable != null) {runnable.walk(OBJECT_START);return null;}- consumeTillMatchingEnd(parser,1,0);+ consumeTillMatchingEnd(parser, 1, 0);return null;default:throw new RuntimeException("Error parsing JSON field value. Unexpected " + JSONParser.getEventString(ev));}}+static abstract class MethodFrameWrapper {Node node;MethodFrameWrapper parent;String name;- void prependName(StringBuilder sb){- if(parent !=null) {+ void prependName(StringBuilder sb) {+ if (parent != null) {parent.prependName(sb);sb.append(DELIM);}@@ -559,11 +562,11 @@ public class JsonRecordReader {for (; ; ) {ev = parser.nextEvent();if (ev == ARRAY_END) {- if(lst.isEmpty()) return null;+ if (lst.isEmpty()) return null;return lst;}Object val = parseSingleFieldValue(ev, parser, runnable);- if(val != null) lst.add(val);+ if (val != null) lst.add(val);}}diff --git a/solr/solrj/src/test/org/apache/solr/common/util/TestJsonRecordReader.java b/solr/solrj/src/test/org/apache/solr/common/util/TestJsonRecordReader.javaindex 2099241296f..0a643ce3800 100644--- a/solr/solrj/src/test/org/apache/solr/common/util/TestJsonRecordReader.java+++ b/solr/solrj/src/test/org/apache/solr/common/util/TestJsonRecordReader.java@@ -27,9 +27,9 @@ import java.util.List;import java.util.Map;-public class TestJsonRecordReader extends SolrTestCaseJ4 {+public class TestJsonRecordReader extends SolrTestCaseJ4 {public void testOneLevelSplit() throws IOException {- String json ="{\n" ++ String json = "{\n" +" \"a\":\"A\" ,\n" +" \"b\":[\n" +" {\"c\":\"C\",\"d\":\"D\" ,\"e\": {\n" +@@ -51,12 +51,12 @@ public class TestJsonRecordReader extends SolrTestCaseJ4 {List<Map<String, Object>> records = streamer.getAllRecords(new StringReader(json));assertEquals(3, records.size());- assertEquals( 3l, ((Map)records.get(0)).get("e_i") );- assertEquals( "D2", ((Map)records.get(2)).get("d_s") );- assertNull( ((Map)records.get(1)).get("e_s") );- assertNull( ((Map)records.get(2)).get("e_s") );- assertNull( ((Map)records.get(1)).get("e_i") );- assertNull( ((Map)records.get(2)).get("e_i") );+ assertEquals(3l, ((Map) records.get(0)).get("e_i"));+ assertEquals("D2", ((Map) records.get(2)).get("d_s"));+ assertNull(((Map) records.get(1)).get("e_s"));+ assertNull(((Map) records.get(2)).get("e_s"));+ assertNull(((Map) records.get(1)).get("e_i"));+ assertNull(((Map) records.get(2)).get("e_i"));// All parameters but /b/c is omittedstreamer = JsonRecordReader.getInst("/b", Arrays.asList(@@ -67,7 +67,7 @@ public class TestJsonRecordReader extends SolrTestCaseJ4 {));records = streamer.getAllRecords(new StringReader(json));for (Map<String, Object> record : records) {- assertNull( record.get("c") );+ assertNull(record.get("c"));}@@ -79,8 +79,8 @@ public class TestJsonRecordReader extends SolrTestCaseJ4 {));records = streamer.getAllRecords(new StringReader(json));for (Map<String, Object> record : records) {- assertNull( record.get("s") );- assertNull( record.get("t") );+ assertNull(record.get("s"));+ assertNull(record.get("t"));}//nested /b/e/* object is completely ignored even though /b/e is mapped@@ -93,13 +93,12 @@ public class TestJsonRecordReader extends SolrTestCaseJ4 {));records = streamer.getAllRecords(new StringReader(json));for (Map<String, Object> record : records) {- assertNull( record.get("s") );- assertNull( record.get("t") );- assertNull( record.get("e") );+ assertNull(record.get("s"));+ assertNull(record.get("t"));+ assertNull(record.get("e"));}-streamer = JsonRecordReader.getInst("/b", Arrays.asList("a_s:/a","c_s:/b/c",@@ -108,18 +107,16 @@ public class TestJsonRecordReader extends SolrTestCaseJ4 {));records = streamer.getAllRecords(new StringReader(json));assertEquals(3, records.size());- assertEquals( 3l, ((Map)records.get(0)).get("t") );- assertEquals( "S", ((Map)records.get(0)).get("s") );- assertNull( ((Map)records.get(1)).get("s") );- assertNull( ((Map)records.get(2)).get("s") );--+ assertEquals(3l, ((Map) records.get(0)).get("t"));+ assertEquals("S", ((Map) records.get(0)).get("s"));+ assertNull(((Map) records.get(1)).get("s"));+ assertNull(((Map) records.get(2)).get("s"));}public void testRecursiveWildCard() throws IOException {- String json ="{\n" ++ String json = "{\n" +" \"a\":\"A\" ,\n" +" \"b\":[\n" +" {\"c\":\"C\",\"d\":\"D\" ,\"e\": {\n" +@@ -135,28 +132,28 @@ public class TestJsonRecordReader extends SolrTestCaseJ4 {streamer = JsonRecordReader.getInst("/b", Collections.singletonList("/b/**"));records = streamer.getAllRecords(new StringReader(json));assertEquals(3, records.size());- assertEquals("records "+records, 3l, ((Map)records.get(0)).get("t") );- assertEquals( "records "+records,"S", ((Map)records.get(0)).get("s") );- assertEquals( "records "+records,3.1234, ((Map)records.get(0)).get("v") );- assertEquals( "records "+records,false, ((Map)records.get(0)).get("w") );+ assertEquals("records " + records, 3l, ((Map) records.get(0)).get("t"));+ assertEquals("records " + records, "S", ((Map) records.get(0)).get("s"));+ assertEquals("records " + records, 3.1234, ((Map) records.get(0)).get("v"));+ assertEquals("records " + records, false, ((Map) records.get(0)).get("w"));for (Map<String, Object> record : records) {- assertNotNull("records "+records,record.get("c"));- assertNotNull("records "+records,record.get("d"));+ assertNotNull("records " + records, record.get("c"));+ assertNotNull("records " + records, record.get("d"));}streamer = JsonRecordReader.getInst("/", Collections.singletonList("/**"));records = streamer.getAllRecords(new StringReader(json));assertEquals(1, records.size());- assertEquals(3, ((List)((Map)records.get(0)).get("c")).size() );- assertEquals(3, ((List)((Map)records.get(0)).get("d")).size() );- assertEquals("records "+records, 3l, ((Map)records.get(0)).get("t") );- assertEquals( "records "+records,"S", ((Map)records.get(0)).get("s") );- assertEquals( "records "+records,"A", ((Map)records.get(0)).get("a") );- assertEquals( "records "+records,false, ((Map)records.get(0)).get("w") );+ assertEquals(3, ((List) ((Map) records.get(0)).get("c")).size());+ assertEquals(3, ((List) ((Map) records.get(0)).get("d")).size());+ assertEquals("records " + records, 3l, ((Map) records.get(0)).get("t"));+ assertEquals("records " + records, "S", ((Map) records.get(0)).get("s"));+ assertEquals("records " + records, "A", ((Map) records.get(0)).get("a"));+ assertEquals("records " + records, false, ((Map) records.get(0)).get("w"));}- public void testRecursiveWildcard2() throws Exception{+ public void testRecursiveWildcard2() throws Exception {String json = "{\n" +" \"first\": \"John\",\n" +" \"last\": \"Doe\",\n" +@@ -190,7 +187,7 @@ public class TestJsonRecordReader extends SolrTestCaseJ4 {records = streamer.getAllRecords(new StringReader(json));assertEquals(2, records.size());for (Map<String, Object> record : records) {- assertEquals(6,record.size());+ assertEquals(6, record.size());assertTrue(record.containsKey("exams.subject"));assertTrue(record.containsKey("exams.test"));assertTrue(record.containsKey("exams.marks"));@@ -199,7 +196,7 @@ public class TestJsonRecordReader extends SolrTestCaseJ4 {streamer = JsonRecordReader.getInst("/", Collections.singletonList("txt:/**"));records = streamer.getAllRecords(new StringReader(json));assertEquals(1, records.size());- assertEquals(9, ((List)records.get(0).get("txt")).size() );+ assertEquals(9, ((List) records.get(0).get("txt")).size());}