PrimeIntellect/SWE-rebench-V2 huggingface dataset:
Repository: networknt/json-schema-validator (java)

Issue:
Invalid (non-string) $schema produces NullPointerException
The following code produces a `NullPointerException`:

```java
JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7);
factory.getSchema("{ \"$schema\": true }");
```

The `$schema` property should be a string but there is no check that it is, in fact, a string.

Note that I have a fix for this I will put up in a PR shortly.

Pull request:
fixes #532 Invalid (non-string) $schema produces NullPointerException

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8e6a153..f99948f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
 
 ### Changed
 
+- fixes #532 Invalid (non-string) $schema produces NullPointerException
+
 ## 1.0.67 - 2022-03-05
 
 ### Changed
diff --git a/src/main/java/com/networknt/schema/JsonSchemaFactory.java b/src/main/java/com/networknt/schema/JsonSchemaFactory.java
index e980066..aa278f1 100644
--- a/src/main/java/com/networknt/schema/JsonSchemaFactory.java
+++ b/src/main/java/com/networknt/schema/JsonSchemaFactory.java
@@ -139,7 +139,7 @@ public class JsonSchemaFactory {
             this.urnFactory = urnFactory;
             return this;
         }
-        
+
         public Builder forceHttps(boolean forceHttps) {
             this.forceHttps = forceHttps;
             return this;
@@ -290,6 +290,9 @@ public class JsonSchemaFactory {
 
     private JsonMetaSchema findMetaSchemaForSchema(final JsonNode schemaNode) {
         final JsonNode uriNode = schemaNode.get("$schema");
+        if (uriNode != null && !uriNode.isNull() && !uriNode.isTextual()) {
+            throw new JsonSchemaException("Unknown MetaSchema: " + uriNode.toString());
+        }
         final String uri = uriNode == null || uriNode.isNull() ? defaultMetaSchemaURI : normalizeMetaSchemaUri(uriNode.textValue(), forceHttps, removeEmptyFragmentSuffix);
         final JsonMetaSchema jsonMetaSchema = jsonMetaSchemas.get(uri);
         if (jsonMetaSchema == null) {


Test patch:
diff --git a/src/test/java/com/networknt/schema/Issue532Test.java b/src/test/java/com/networknt/schema/Issue532Test.java
new file mode 100644
index 0000000..bb380cd
--- /dev/null
+++ b/src/test/java/com/networknt/schema/Issue532Test.java
@@ -0,0 +1,16 @@
+package com.networknt.schema;
+
+import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+public class Issue532Test {
+    @Test
+    public void failure() {
+        JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7);
+        JsonSchemaException ex = assertThrows(JsonSchemaException.class, () -> {
+            factory.getSchema("{ \"$schema\": true }");
+        });
+        assertEquals("Unknown MetaSchema: true", ex.getMessage());
+    }
+}