Skip to content

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

@richardwalsh

Description

@richardwalsh

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions