2
Genson的內部庫代碼導致ArrayIndexOutOfBoundsException,因爲它試圖索引一個我認爲是null的數組。見下文。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]。當我調試它說方法是「錯誤」。它試圖在結果列表中的MyObject有以下幾種方法進行操作(只顯示失敗的方法):
@XmlElement(nillable=true)
public String getError() {
return error;
}
public void setError(String error) {
this.error = error;
}
如何解決這個bug?爲什麼Genson在做?
尋呼@eugen - 任何想法爲什麼會發生這種情況:) – KyleM
你可以用一個測試用例來打開一個問題[這裏](https://github.com/owlike/genson/issues)來重現它嗎?從我們掌握的信息來看,沒有什麼明顯的 – eugen