3131public class UnionTypeValidator extends BaseJsonValidator implements JsonValidator {
3232 private static final Logger logger = LoggerFactory .getLogger (UnionTypeValidator .class );
3333
34- private final List <JsonValidator > schemas = new ArrayList <>() ;
34+ private final List <JsonValidator > schemas ;
3535 private final String error ;
3636
3737 public UnionTypeValidator (SchemaLocation schemaLocation , JsonNodePath evaluationPath , JsonNode schemaNode , JsonSchema parentSchema , ValidationContext validationContext ) {
@@ -41,21 +41,24 @@ public UnionTypeValidator(SchemaLocation schemaLocation, JsonNodePath evaluation
4141 String sep = "" ;
4242 errorBuilder .append ('[' );
4343
44- if (!schemaNode .isArray ())
44+ if (!schemaNode .isArray ()) {
4545 throw new JsonSchemaException ("Expected array for type property on Union Type Definition." );
46+ }
4647
4748 int i = 0 ;
49+ this .schemas = new ArrayList <>(schemaNode .size ());
4850 for (JsonNode n : schemaNode ) {
4951 JsonType t = TypeFactory .getSchemaNodeType (n );
5052 errorBuilder .append (sep ).append (t );
5153 sep = ", " ;
5254
53- if (n .isObject ())
55+ if (n .isObject ()) {
5456 schemas .add (validationContext .newSchema (schemaLocation .append (ValidatorTypeCode .TYPE .getValue ()),
5557 evaluationPath .append (ValidatorTypeCode .TRUE .getValue ()), n , parentSchema ));
56- else
57- schemas .add (new TypeValidator (schemaLocation .append (i ), evaluationPath .append (i ), n , parentSchema , validationContext ));
58-
58+ } else {
59+ schemas .add (new TypeValidator (schemaLocation .append (i ), evaluationPath .append (i ), n , parentSchema ,
60+ validationContext ));
61+ }
5962 i ++;
6063 }
6164
0 commit comments