Skip to content

Commit

Permalink
Merge pull request #13 from andrejserafim/npe
Browse files Browse the repository at this point in the history
checking for null additional names.
  • Loading branch information
erosb committed Nov 23, 2015
2 parents feb466e + 5623f7d commit 22da969
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
13 changes: 9 additions & 4 deletions core/src/main/java/org/everit/json/schema/ObjectSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,15 @@ private void testAdditionalProperties(final JSONObject subject) {
}

private Stream<String> getAdditionalProperties(final JSONObject subject) {
return Arrays
.stream(JSONObject.getNames(subject))
.filter(key -> !propertySchemas.containsKey(key))
.filter(key -> !matchesAnyPattern(key));
String[] names = JSONObject.getNames(subject);
if (names == null) {
return Stream.empty();
} else {
return Arrays
.stream(names)
.filter(key -> !propertySchemas.containsKey(key))
.filter(key -> !matchesAnyPattern(key));
}
}

private void testProperties(final JSONObject subject) {
Expand Down
39 changes: 39 additions & 0 deletions tests/src/test/java/org/everit/json/schema/EmptyObjectTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2011 Everit Kft. (http://www.everit.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.everit.json.schema;

import org.everit.json.schema.loader.SchemaLoader;
import org.json.JSONObject;
import org.json.JSONTokener;
import org.junit.Test;

public class EmptyObjectTest {
@Test
public void validateEmptyObject() {

JSONObject jsonSchema = new JSONObject(new JSONTokener(
MetaSchemaTest.class
.getResourceAsStream("/org/everit/json/schema/json-schema-draft-04.json")));

JSONObject jsonSubject = new JSONObject("{\n" +
" \"type\": \"object\",\n" +
" \"properties\": {}\n" +
"}");

Schema schema = SchemaLoader.load(jsonSchema);
schema.validate(jsonSubject);
}
}

0 comments on commit 22da969

Please sign in to comment.