Genson抛出ArrayIndexOutOfBoundsException

时间:2016-07-06 23:10:37

标签: java json genson

Genson的内部库代码导致ArrayIndexOutOfBoundsException,因为它试图索引一个我假设为null的数组。见下文。

我得到以下堆栈跟踪:

Directory.Delete(string directoryName, bool recursive);

这是由Genson库中的以下方法引起的:

DirectoryInfo ImageFolder = new DirectoryInfo(Program.FolderPath + @"\Images");
foreach (var fileInfo in ImageFolder.GetFiles())
{
    fileInfo.Delete(); //this is FileInfo.Delete
    // or
    // File.Delete(fileInfo.FullName);
    // dont use reserve "File" as your variable name
}

它来自方法中的以下代码: method.getGenericParameterTypes()[0] 。当我调试它说方法是“错误”。它正在尝试在List上进行操作,其中MyObject具有以下方法(仅显示失败方法):

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会这样做?

1 个答案:

答案 0 :(得分:0)

This was indeed a bug and has been fixed in this commit. The fix will be part of release 1.5.