jsonschemafriend icon indicating copy to clipboard operation
jsonschemafriend copied to clipboard

Example from specification fails with NPE

Open olegshtch opened this issue 4 years ago • 4 comments

I've prepared test suite based on https://json-schema.org/draft/2020-12/json-schema-core.html#recursive-example in https://github.com/json-schema-org/JSON-Schema-Test-Suite/pull/521

Currently it fails with NullPointerException:

java.lang.NullPointerException
	at net.jimblackler.jsonschemafriend.Validator.validate(Validator.java:95)
	at net.jimblackler.jsonschemafriend.Validator.validate(Validator.java:179)
	at net.jimblackler.jsonschemafriend.Validator.validate(Validator.java:76)
	at net.jimblackler.jsonschemafriend.Validator.validate(Validator.java:412)
	at net.jimblackler.jsonschemafriend.Validator.validate(Validator.java:76)
	at net.jimblackler.jsonschemafriend.Validator.validate(Validator.java:505)
	at net.jimblackler.jsonschemafriend.Validator.validate(Validator.java:156)
	at net.jimblackler.jsonschemafriend.Validator.validate(Validator.java:71)
	at net.jimblackler.jsonschemafriend.SuiteTest.lambda$scan$1(SuiteTest.java:100)

olegshtch avatar Oct 14 '21 18:10 olegshtch

I tested it this way and it worked:

{
  "$defs": {
    "tree": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "$id": "https://example.com/tree",
      "$dynamicAnchor": "node",
      "type": "object",
      "properties": {
        "data": true,
        "children": {
          "type": "array",
          "items": {
            "$dynamicRef": "#node"
          }
        }
      }
    }
  },
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://example.com/strict-tree",
  "$dynamicAnchor": "node",
  "$ref": "tree",
  "unevaluatedProperties": false
}
{
    "children": [ { "daat": 1 } ]
}

But I will attempt to patch your test locally and see what happens.

jimblackler avatar Oct 14 '21 19:10 jimblackler

Maybe it doesn't work because tree schema in other file.

olegshtch avatar Oct 14 '21 19:10 olegshtch

Step one is to not NPE if $dynamicAnchor doesn't resolve, which is obviously bad. https://github.com/jimblackler/jsonschemafriend/commit/c2d871f19a3e83a24fdbf5ff6a3b195e0c586e0a

It doesn't fix your test case though so I'll look more into that.

jimblackler avatar Oct 14 '21 20:10 jimblackler

OK the issue is the port spec in the URL http://localhost:1234/strict-tree.json. The library was mishandling those. https://github.com/jimblackler/jsonschemafriend/commit/e5d884a8499c820313767cc492f5e0463c0c8559 contains fixes for this specific test case (although it's possible there are more).

jimblackler avatar Oct 14 '21 23:10 jimblackler