Skip to content

Commit 22da969

Browse files
committed
Merge pull request #13 from andrejserafim/npe
checking for null additional names.
2 parents feb466e + 5623f7d commit 22da969

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

core/src/main/java/org/everit/json/schema/ObjectSchema.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,15 @@ private void testAdditionalProperties(final JSONObject subject) {
255255
}
256256

257257
private Stream<String> getAdditionalProperties(final JSONObject subject) {
258-
return Arrays
259-
.stream(JSONObject.getNames(subject))
260-
.filter(key -> !propertySchemas.containsKey(key))
261-
.filter(key -> !matchesAnyPattern(key));
258+
String[] names = JSONObject.getNames(subject);
259+
if (names == null) {
260+
return Stream.empty();
261+
} else {
262+
return Arrays
263+
.stream(names)
264+
.filter(key -> !propertySchemas.containsKey(key))
265+
.filter(key -> !matchesAnyPattern(key));
266+
}
262267
}
263268

264269
private void testProperties(final JSONObject subject) {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (C) 2011 Everit Kft. (http://www.everit.org)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.everit.json.schema;
17+
18+
import org.everit.json.schema.loader.SchemaLoader;
19+
import org.json.JSONObject;
20+
import org.json.JSONTokener;
21+
import org.junit.Test;
22+
23+
public class EmptyObjectTest {
24+
@Test
25+
public void validateEmptyObject() {
26+
27+
JSONObject jsonSchema = new JSONObject(new JSONTokener(
28+
MetaSchemaTest.class
29+
.getResourceAsStream("/org/everit/json/schema/json-schema-draft-04.json")));
30+
31+
JSONObject jsonSubject = new JSONObject("{\n" +
32+
" \"type\": \"object\",\n" +
33+
" \"properties\": {}\n" +
34+
"}");
35+
36+
Schema schema = SchemaLoader.load(jsonSchema);
37+
schema.validate(jsonSubject);
38+
}
39+
}

0 commit comments

Comments
 (0)