mirror of https://github.com/apache/lucene.git
SOLR-14819: Fix inefficient iterator pattern in JsonSchemaValidator.
This commit is contained in:
parent
4fa4329287
commit
22abecdbc1
|
@ -181,6 +181,8 @@ 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
|
||||
---------------------
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue