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

Exception thrown for empty string enum value. #58

Closed
joelittlejohn opened this issue Jun 23, 2013 · 2 comments
Closed

Exception thrown for empty string enum value. #58

joelittlejohn opened this issue Jun 23, 2013 · 2 comments
Milestone

Comments

@joelittlejohn
Copy link
Owner

Original author: [email protected] (July 06, 2012 17:09:51)

What steps will reproduce the problem?

  1. Generate Java code from test.json:
    {
    "id": "test",
    "type": "object",
    "additionalProperties": false,
    "properties": {
    "gender": {
    "type": "string",
    "default": "",
    "enum": [ "", "male", "female" ]
    }
    }
    }

What is the expected output?
Test.java

What do you see instead?
Program aborts with StringIndexOutOfBoundsException (full stack trace below).

What version of the product are you using?
0.3.0

On what Java version?
java version "1.6.0_30"

Replacing this code (EnumRule.getConstantName(EnumRule.java:188)):
if (Character.isDigit(enumName.charAt(0))) {
enumName = "" + enumName;
}
with this code:
if( enumName.length() == 0 ){
enumName = "EMPTY";
}else if (Character.isDigit(enumName.charAt(0))) {
enumName = "
" + enumName;
}
resolves the issue.

Stack Trace:

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 0
at java.lang.String.charAt(Unknown Source)
at com.googlecode.jsonschema2pojo.rules.EnumRule.getConstantName(EnumRule.java:188)
at com.googlecode.jsonschema2pojo.rules.EnumRule.addEnumConstants(EnumRule.java:162)
at com.googlecode.jsonschema2pojo.rules.EnumRule.apply(EnumRule.java:99)
at com.googlecode.jsonschema2pojo.rules.EnumRule.apply(EnumRule.java:1)
at com.googlecode.jsonschema2pojo.rules.JsonSchemaRule.apply(JsonSchemaRule.java:71)
at com.googlecode.jsonschema2pojo.rules.JsonSchemaRule.apply(JsonSchemaRule.java:1)
at com.googlecode.jsonschema2pojo.rules.PropertyRule.apply(PropertyRule.java:77)
at com.googlecode.jsonschema2pojo.rules.PropertyRule.apply(PropertyRule.java:1)
at com.googlecode.jsonschema2pojo.rules.PropertiesRule.apply(PropertiesRule.java:62)
at com.googlecode.jsonschema2pojo.rules.PropertiesRule.apply(PropertiesRule.java:1)
at com.googlecode.jsonschema2pojo.rules.ObjectRule.apply(ObjectRule.java:108)
at com.googlecode.jsonschema2pojo.rules.ObjectRule.apply(ObjectRule.java:1)
at com.googlecode.jsonschema2pojo.rules.TypeRule.apply(TypeRule.java:95)
at com.googlecode.jsonschema2pojo.rules.TypeRule.apply(TypeRule.java:1)
at com.googlecode.jsonschema2pojo.rules.JsonSchemaRule.apply(JsonSchemaRule.java:73)
at com.googlecode.jsonschema2pojo.rules.JsonSchemaRule.apply(JsonSchemaRule.java:66)
at com.googlecode.jsonschema2pojo.rules.JsonSchemaRule.apply(JsonSchemaRule.java:1)
at com.googlecode.jsonschema2pojo.SchemaMapperImpl.generate(SchemaMapperImpl.java:65)
at com.googlecode.jsonschema2pojo.cli.Jsonschema2Pojo.generate(Jsonschema2Pojo.java:92)
at com.googlecode.jsonschema2pojo.cli.Jsonschema2Pojo.main(Jsonschema2Pojo.java:60)

Original issue: http://code.google.com/p/jsonschema2pojo/issues/detail?id=58

@joelittlejohn
Copy link
Owner Author

From [email protected] on July 06, 2012 18:48:17
Thanks John. I'll add this to the next release.

@joelittlejohn
Copy link
Owner Author

From [email protected] on July 06, 2012 21:00:46
Fixed in 0.3.1.

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

No branches or pull requests

1 participant