Skip to content
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

Schema with required[""] results in String index out of range: 0 #725

Closed
richardwalsh opened this issue May 12, 2017 · 2 comments
Closed
Milestone

Comments

@richardwalsh
Copy link

Example file:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "Silly",
    "type":"object",
    "description":"silly example",
    "required": [""],
    "properties": {
        "code" : {
            "type":"string",
            "description":"blah blah blah"
        }
    }
}

maven plugin error:

Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 0
	at java.lang.String.charAt(String.java:658)
	at org.jsonschema2pojo.util.NameHelper.normalizeName(NameHelper.java:45)
	at org.jsonschema2pojo.util.NameHelper.getPropertyName(NameHelper.java:74)
	at org.jsonschema2pojo.rules.RequiredArrayRule.apply(RequiredArrayRule.java:54)
	at org.jsonschema2pojo.rules.RequiredArrayRule.apply(RequiredArrayRule.java:39)
	at org.jsonschema2pojo.rules.ObjectRule.apply(ObjectRule.java:134)
	at org.jsonschema2pojo.rules.ObjectRule.apply(ObjectRule.java:64)
	at org.jsonschema2pojo.rules.TypeRule.apply(TypeRule.java:85)
	at org.jsonschema2pojo.rules.TypeRule.apply(TypeRule.java:35)
	at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:73)
	at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:66)
	at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:30)
	at org.jsonschema2pojo.SchemaMapper.generate(SchemaMapper.java:88)
	at org.jsonschema2pojo.Jsonschema2Pojo.generateRecursive(Jsonschema2Pojo.java:116)
	at org.jsonschema2pojo.Jsonschema2Pojo.generateRecursive(Jsonschema2Pojo.java:118)
	at org.jsonschema2pojo.Jsonschema2Pojo.generate(Jsonschema2Pojo.java:74)
	at org.jsonschema2pojo.maven.Jsonschema2PojoMojo.execute(Jsonschema2PojoMojo.java:494)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106)

Notes:

  1. I upgraded my pom to use the latest maven plugin version (0.4.34) from 0.4.7 and the error started showing up. I narrowed it down to 0.4.12 works fine but then fails in version 0.4.13.

  2. Yes, required[""] is pointless, I inherited the schema and don't know the history behind it. The easy workaround is simply removing the "required" and everything is fine.

Thanks,
Rich

@joelittlejohn
Copy link
Owner

Thanks for reporting this. An easy one to fix I expect and nice to make the plugin less fragile if we can.

michalkolodziejski added a commit to michalkolodziejski/jsonschema2pojo that referenced this issue May 25, 2017
michalkolodziejski added a commit to michalkolodziejski/jsonschema2pojo that referenced this issue May 25, 2017
@joelittlejohn joelittlejohn changed the title maven plugin: schema with required[""] results in String index out of range: 0 Schema with required[""] results in String index out of range: 0 May 30, 2017
@joelittlejohn joelittlejohn added this to the 0.4.36 milestone May 30, 2017
@joelittlejohn
Copy link
Owner

Fixed by #733

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