You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by br...@apache.org on 2020/09/03 10:22:28 UTC
[lucene-solr] branch branch_8x updated: SOLR-14819: Fix inefficient
iterator pattern in JsonSchemaValidator.
This is an automated email from the ASF dual-hosted git repository.
broustant pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
The following commit(s) were added to refs/heads/branch_8x by this push:
new c8fcf1b SOLR-14819: Fix inefficient iterator pattern in JsonSchemaValidator.
c8fcf1b is described below
commit c8fcf1b5b301b1b83852ccc60f228f12833d8287
Author: Bruno Roustant <br...@salesforce.com>
AuthorDate: Thu Sep 3 11:49:49 2020 +0200
SOLR-14819: Fix inefficient iterator pattern in JsonSchemaValidator.
---
solr/CHANGES.txt | 1 +
.../solr/common/util/JsonSchemaValidator.java | 26 ++++++++--------------
2 files changed, 10 insertions(+), 17 deletions(-)
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index bcf1003..11e025d 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -62,6 +62,7 @@ Optimizations
* SOLR-14422: Admin UI shows Angular placeholders on first load / refresh. (Colvin Cowie via Eric Pugh)
+* SOLR-14819: Fix inefficient iterator pattern in JsonSchemaValidator. (Thomas DuBuisson via Bruno Roustant)
Bug Fixes
---------------------
diff --git a/solr/solrj/src/java/org/apache/solr/common/util/JsonSchemaValidator.java b/solr/solrj/src/java/org/apache/solr/common/util/JsonSchemaValidator.java
index 1a2d1c7..d67e6eb 100644
--- a/solr/solrj/src/java/org/apache/solr/common/util/JsonSchemaValidator.java
+++ b/solr/solrj/src/java/org/apache/solr/common/util/JsonSchemaValidator.java
@@ -17,15 +17,7 @@
package org.apache.solr.common.util;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
import java.util.function.Function;
/**
@@ -46,15 +38,16 @@ public class JsonSchemaValidator {
this((Map) Utils.fromJSONString(jsonString));
}
- public JsonSchemaValidator(Map jsonSchema) {
+ public JsonSchemaValidator(Map<?, ?> jsonSchema) {
this.validators = new LinkedList<>();
- for (Object fname : jsonSchema.keySet()) {
+ for (Map.Entry<?, ?> entry : jsonSchema.entrySet()) {
+ Object fname = entry.getKey();
if (KNOWN_FNAMES.contains(fname.toString())) continue;
Function<Pair<Map, Object>, Validator> initializeFunction = VALIDATORS.get(fname.toString());
if (initializeFunction == null) throw new RuntimeException("Unknown key : " + fname);
- this.validators.add(initializeFunction.apply(new Pair<>(jsonSchema, jsonSchema.get(fname))));
+ this.validators.add(initializeFunction.apply(new Pair<>(jsonSchema, entry.getValue())));
}
}
@@ -276,18 +269,17 @@ class PropertiesValidator extends Validator<Map<String, Map>> {
}
@Override
- @SuppressWarnings({"rawtypes"})
boolean validate(Object o, List<String> errs) {
if (o instanceof Map) {
- @SuppressWarnings({"rawtypes"})
- Map map = (Map) o;
- for (Object key : map.keySet()) {
+ Map<?, ?> map = (Map) o;
+ for (Map.Entry<?,?> entry : map.entrySet()) {
+ Object key = entry.getKey();
JsonSchemaValidator jsonSchema = jsonSchemas.get(key.toString());
if (jsonSchema == null && !additionalProperties) {
errs.add("Unknown field '" + key + "' in object : " + Utils.toJSONString(o));
return false;
}
- if (jsonSchema != null && !jsonSchema.validate(map.get(key), errs)) {
+ if (jsonSchema != null && !jsonSchema.validate(entry.getValue(), errs)) {
return false;
}
}