AArhin / orika

Automatically exported from code.google.com/p/orika
0 stars 0 forks source link

Indirect inheritance with parameter reducing leads to java.lang.ArrayIndexOutOfBoundsException #190

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What version of Orika are you using?

1.4.5

Please mind that it is required to provide a test of the issue with all
relevant comments. Thank you

Issue:

inheritance with parameter reducing. DomainBiLongConverter reduce class 
parameters from 2 to 1. See example classes

public abstract class DomainBiLongConverter<D extends IDomain> extends 
BidirectionalConverter<D, Long> {

    @Override
    public Long convertTo(final D source, final Type<Long> type) {
        return source == null ? null : source.getId();
    }

    @Override
    public D convertFrom(final Long source, final Type<D> type) {
        return source == null ? null : get(source);
    }

    abstract protected D get(Long id);

}

public class RezervationUnitBiLongConverter extends 
DomainBiLongConverter<IReservationUnit> {

    @Autowired private IReservationUnitManager manager;

    @Override
    protected IReservationUnit get(final Long id) {
        return manager.getReservationUnit(id);
    }

}

The exception:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to 
instantiate 
[com.jresearchsoft.booking.gwt.server.orika.RezervationUnitBiLongConverter]: 
Constructor threw exception; nested exception is 
java.lang.ArrayIndexOutOfBoundsException: 1
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:89)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1086)
    ... 33 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
    at ma.glasnost.orika.CustomConverter.<init>(CustomConverter.java:50)
    at ma.glasnost.orika.converter.BidirectionalConverter.<init>(BidirectionalConverter.java:34)
    at com.jresearchsoft.booking.gwt.server.orika.DomainBiLongConverter.<init>(DomainBiLongConverter.java:12)
    at com.jresearchsoft.booking.gwt.server.orika.RezervationUnitBiLongConverter.<init>(RezervationUnitBiLongConverter.java:14)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
    ... 35 more

Original issue reported on code.google.com by sspirido...@gmail.com on 30 Jan 2015 at 8:07

GoogleCodeExporter commented 8 years ago
You should subclass directly CustomConverter, BidirectionalConverter expect two 
arguments

Original comment by elaat...@gmail.com on 2 Feb 2015 at 12:46

GoogleCodeExporter commented 8 years ago
But I use the BidirectionalConverter functionality. Now I use following 
workaround:

public abstract class DomainBiLongConverter<D extends IDomain, L extends 
Number> extends BidirectionalConverter<D, L> {
//...
}

public class RezervationUnitBiLongConverter extends 
DomainBiLongConverter<IReservationUnit, Long> {
//...
}

It works, but it looks very ugly :(

Stas

Original comment by sspirido...@gmail.com on 2 Feb 2015 at 9:16