Genson 抛出 ArrayIndexOutOfBoundsException
Genson throws ArrayIndexOutOfBoundsException
Genson 的内部库代码导致 ArrayIndexOutOfBoundsException,因为它正在尝试索引一个我认为为空的数组。见下文。
我得到以下堆栈跟踪:
Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
at com.owlike.genson.reflect.BeanPropertyFactory$StandardFactory.createMutator(BeanPropertyFactory.java:115)
at com.owlike.genson.reflect.BeanPropertyFactory$CompositeFactory.createMutator(BeanPropertyFactory.java:87)
at com.owlike.genson.reflect.BaseBeanDescriptorProvider.provideMethodMutators(BaseBeanDescriptorProvider.java:232)
at com.owlike.genson.reflect.BaseBeanDescriptorProvider.provideBeanPropertyMutators(BaseBeanDescriptorProvider.java:119)
at com.owlike.genson.reflect.AbstractBeanDescriptorProvider.provide(AbstractBeanDescriptorProvider.java:98)
at com.owlike.genson.reflect.BeanDescriptorProvider$CompositeBeanDescriptorProvider.provide(BeanDescriptorProvider.java:60)
at com.owlike.genson.convert.BasicConvertersFactory.provide(BasicConvertersFactory.java:104)
at com.owlike.genson.convert.BasicConvertersFactory.create(BasicConvertersFactory.java:69)
at com.owlike.genson.convert.BasicConvertersFactory.create(BasicConvertersFactory.java:51)
at com.owlike.genson.reflect.AbstractBeanDescriptorProvider$ContextualFactoryDecorator.create(AbstractBeanDescriptorProvider.java:75)
at com.owlike.genson.reflect.AbstractBeanDescriptorProvider$ContextualFactoryDecorator.create(AbstractBeanDescriptorProvider.java:64)
at com.owlike.genson.convert.ChainedFactory.create(ChainedFactory.java:88)
at com.owlike.genson.convert.ChainedFactory.create(ChainedFactory.java:75)
at com.owlike.genson.convert.ChainedFactory.create(ChainedFactory.java:88)
at com.owlike.genson.convert.ChainedFactory.create(ChainedFactory.java:75)
at com.owlike.genson.convert.CircularClassReferenceConverterFactory.create(CircularClassReferenceConverterFactory.java:55)
at com.owlike.genson.convert.CircularClassReferenceConverterFactory.create(CircularClassReferenceConverterFactory.java:19)
at com.owlike.genson.Genson.provideConverter(Genson.java:148)
at com.owlike.genson.convert.DefaultConverters$CollectionConverterFactory.create(DefaultConverters.java:239)
at com.owlike.genson.convert.DefaultConverters$CollectionConverterFactory.create(DefaultConverters.java:231)
at com.owlike.genson.convert.BasicConvertersFactory.provide(BasicConvertersFactory.java:97)
at com.owlike.genson.convert.BasicConvertersFactory.create(BasicConvertersFactory.java:69)
at com.owlike.genson.convert.BasicConvertersFactory.create(BasicConvertersFactory.java:51)
at com.owlike.genson.reflect.AbstractBeanDescriptorProvider$ContextualFactoryDecorator.create(AbstractBeanDescriptorProvider.java:75)
at com.owlike.genson.reflect.AbstractBeanDescriptorProvider$ContextualFactoryDecorator.create(AbstractBeanDescriptorProvider.java:64)
at com.owlike.genson.convert.ChainedFactory.create(ChainedFactory.java:88)
at com.owlike.genson.convert.ChainedFactory.create(ChainedFactory.java:75)
at com.owlike.genson.convert.ChainedFactory.create(ChainedFactory.java:88)
at com.owlike.genson.convert.ChainedFactory.create(ChainedFactory.java:75)
at com.owlike.genson.convert.CircularClassReferenceConverterFactory.create(CircularClassReferenceConverterFactory.java:55)
at com.owlike.genson.convert.CircularClassReferenceConverterFactory.create(CircularClassReferenceConverterFactory.java:19)
at com.owlike.genson.Genson.provideConverter(Genson.java:148)
at com.owlike.genson.Genson.serialize(Genson.java:272)
at com.owlike.genson.ext.jaxrs.GensonJsonConverter.writeTo(GensonJsonConverter.java:85)
由以下Genson库方法引起:
public PropertyMutator createMutator(String name, Method method, Type ofType, Genson genson) {
Type expandedType = TypeUtil.expandType(method.getGenericParameterTypes()[0], ofType);
return new PropertyMutator.MethodMutator(name, method, expandedType,
getRawClass(ofType));
}
它来自方法中的以下代码:method.getGenericParameterTypes()[0]。当我调试时,它说方法是 "error"。它正在尝试对 List 进行操作,其中 MyObject 具有以下方法(仅显示失败的方法):
@XmlElement(nillable=true)
public String getError() {
return error;
}
public void setError(String error) {
this.error = error;
}
我该如何解决这个错误?为什么 Genson 这样做?
这确实是一个错误,已在 this commit 中修复。修复将成为 1.5 版的一部分。
Genson 的内部库代码导致 ArrayIndexOutOfBoundsException,因为它正在尝试索引一个我认为为空的数组。见下文。
我得到以下堆栈跟踪:
Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
at com.owlike.genson.reflect.BeanPropertyFactory$StandardFactory.createMutator(BeanPropertyFactory.java:115)
at com.owlike.genson.reflect.BeanPropertyFactory$CompositeFactory.createMutator(BeanPropertyFactory.java:87)
at com.owlike.genson.reflect.BaseBeanDescriptorProvider.provideMethodMutators(BaseBeanDescriptorProvider.java:232)
at com.owlike.genson.reflect.BaseBeanDescriptorProvider.provideBeanPropertyMutators(BaseBeanDescriptorProvider.java:119)
at com.owlike.genson.reflect.AbstractBeanDescriptorProvider.provide(AbstractBeanDescriptorProvider.java:98)
at com.owlike.genson.reflect.BeanDescriptorProvider$CompositeBeanDescriptorProvider.provide(BeanDescriptorProvider.java:60)
at com.owlike.genson.convert.BasicConvertersFactory.provide(BasicConvertersFactory.java:104)
at com.owlike.genson.convert.BasicConvertersFactory.create(BasicConvertersFactory.java:69)
at com.owlike.genson.convert.BasicConvertersFactory.create(BasicConvertersFactory.java:51)
at com.owlike.genson.reflect.AbstractBeanDescriptorProvider$ContextualFactoryDecorator.create(AbstractBeanDescriptorProvider.java:75)
at com.owlike.genson.reflect.AbstractBeanDescriptorProvider$ContextualFactoryDecorator.create(AbstractBeanDescriptorProvider.java:64)
at com.owlike.genson.convert.ChainedFactory.create(ChainedFactory.java:88)
at com.owlike.genson.convert.ChainedFactory.create(ChainedFactory.java:75)
at com.owlike.genson.convert.ChainedFactory.create(ChainedFactory.java:88)
at com.owlike.genson.convert.ChainedFactory.create(ChainedFactory.java:75)
at com.owlike.genson.convert.CircularClassReferenceConverterFactory.create(CircularClassReferenceConverterFactory.java:55)
at com.owlike.genson.convert.CircularClassReferenceConverterFactory.create(CircularClassReferenceConverterFactory.java:19)
at com.owlike.genson.Genson.provideConverter(Genson.java:148)
at com.owlike.genson.convert.DefaultConverters$CollectionConverterFactory.create(DefaultConverters.java:239)
at com.owlike.genson.convert.DefaultConverters$CollectionConverterFactory.create(DefaultConverters.java:231)
at com.owlike.genson.convert.BasicConvertersFactory.provide(BasicConvertersFactory.java:97)
at com.owlike.genson.convert.BasicConvertersFactory.create(BasicConvertersFactory.java:69)
at com.owlike.genson.convert.BasicConvertersFactory.create(BasicConvertersFactory.java:51)
at com.owlike.genson.reflect.AbstractBeanDescriptorProvider$ContextualFactoryDecorator.create(AbstractBeanDescriptorProvider.java:75)
at com.owlike.genson.reflect.AbstractBeanDescriptorProvider$ContextualFactoryDecorator.create(AbstractBeanDescriptorProvider.java:64)
at com.owlike.genson.convert.ChainedFactory.create(ChainedFactory.java:88)
at com.owlike.genson.convert.ChainedFactory.create(ChainedFactory.java:75)
at com.owlike.genson.convert.ChainedFactory.create(ChainedFactory.java:88)
at com.owlike.genson.convert.ChainedFactory.create(ChainedFactory.java:75)
at com.owlike.genson.convert.CircularClassReferenceConverterFactory.create(CircularClassReferenceConverterFactory.java:55)
at com.owlike.genson.convert.CircularClassReferenceConverterFactory.create(CircularClassReferenceConverterFactory.java:19)
at com.owlike.genson.Genson.provideConverter(Genson.java:148)
at com.owlike.genson.Genson.serialize(Genson.java:272)
at com.owlike.genson.ext.jaxrs.GensonJsonConverter.writeTo(GensonJsonConverter.java:85)
由以下Genson库方法引起:
public PropertyMutator createMutator(String name, Method method, Type ofType, Genson genson) {
Type expandedType = TypeUtil.expandType(method.getGenericParameterTypes()[0], ofType);
return new PropertyMutator.MethodMutator(name, method, expandedType,
getRawClass(ofType));
}
它来自方法中的以下代码:method.getGenericParameterTypes()[0]。当我调试时,它说方法是 "error"。它正在尝试对 List 进行操作,其中 MyObject 具有以下方法(仅显示失败的方法):
@XmlElement(nillable=true)
public String getError() {
return error;
}
public void setError(String error) {
this.error = error;
}
我该如何解决这个错误?为什么 Genson 这样做?
这确实是一个错误,已在 this commit 中修复。修复将成为 1.5 版的一部分。