Skip to content

.getSchema() will stack overflow on recursive definitions. #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
juiposa opened this issue Feb 5, 2018 · 1 comment
Closed

.getSchema() will stack overflow on recursive definitions. #59

juiposa opened this issue Feb 5, 2018 · 1 comment

Comments

@juiposa
Copy link

juiposa commented Feb 5, 2018

With v0.1.13

I have a schema file with an recursive object, i.e. a parent object that can have a child object with the same schema.

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "parent": {
      "$ref": "#/definitions/objectDef"
    }
  }
},
"definitions": {
  "objectDef": {
    "type": "object",
    "properties": {
      "value1": {
        "type": "string"
      },
      "value2": {
        "type": "string"
      },
      "childObject": {
        "$ref": "#/definitions/objectDef"
      }
    }
  }
}

It seems to not like this, as when I attempt to call schemaFactory.getSchema(node), it errors out with a stack overflow

com.networknt.schema.JsonSchemaException: java.lang.StackOverflowError
at com.networknt.schema.JsonMetaSchema.newValidator(JsonMetaSchema.java:247)
at com.networknt.schema.ValidationContext.newValidator(ValidationContext.java:24)
at com.networknt.schema.JsonSchema.read(JsonSchema.java:116)
at com.networknt.schema.JsonSchema.<init>(JsonSchema.java:56)
at com.networknt.schema.JsonSchema.<init>(JsonSchema.java:49)
at com.networknt.schema.AnyOfValidator.<init>(AnyOfValidator.java:38)
at sun.reflect.GeneratedConstructorAccessor8.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.networknt.schema.ValidatorTypeCode.newValidator(ValidatorTypeCode.java:102)
...
Cause: java.lang.StackOverflowError:
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)

I updated to v0.1.13 today from v0.1.7, where it returned the JsonSchema object for the above schema without issue.

@stevehu
Copy link
Contributor

stevehu commented Feb 5, 2018

I think one of the contributors has fixed this issue in #36

Thanks a lot for your confirmation. This is how community works:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants