Giter Site home page Giter Site logo

CustomMapper ArrayIndexOutOfBoundsException if an intermediate generic superclass is used for a mapper implementation about orika HOT 5 CLOSED

orika-mapper avatar orika-mapper commented on August 18, 2024
CustomMapper ArrayIndexOutOfBoundsException if an intermediate generic superclass is used for a mapper implementation

from orika.

Comments (5)

elaatifi avatar elaatifi commented on August 18, 2024

Thanks Adam !

from orika.

elaatifi avatar elaatifi commented on August 18, 2024

Forget to mention that you can fix them manually (aType,bType) in the subclass constructor as a workaround

from orika.

adammichalik avatar adammichalik commented on August 18, 2024

Unfortunately I don't think it's possible in that particular case. Since CustomMapper constructor has:

public CustomMapper() {
        java.lang.reflect.Type genericSuperclass = getClass().getGenericSuperclass();
        if (genericSuperclass != null && genericSuperclass instanceof ParameterizedType) {
            ParameterizedType superType = (ParameterizedType)getClass().getGenericSuperclass();
            try {
                aType = TypeFactory.valueOf(superType.getActualTypeArguments()[0]);
                bType = TypeFactory.valueOf(superType.getActualTypeArguments()[1]);
            } catch (IllegalArgumentException e) {
                /* do nothing; this was not extended by a user 
                 * getXXType methods must be manually overridden 
                 */
            }
        }
    }

You can see that (referring to my example) if I construct ConcreteMapper its constructor has to call a constructor of GenericSuperMapper and this in turn calls the constructor of Orika's CustomMapper.

There in CustomMapper constructor, this is ConcreteMapper, so genericSuperclass becomes the GenericSuperMapper generic type, which is still an instance of ParameterizedType. So superType is also equal to the GenericSuperMapper generic type (we could just cast genericSuperclass instead of calling getClass().getGenericSuperclass() again btw.).

But GenericSuperMapper itself has only one type parameter, so the line

 bType = TypeFactory.valueOf(superType.getActualTypeArguments()[1]);

fails with ArrayIndexOutOfBoundsException. The try/catch block catches only IllegalArgumentException, so the ArrayIndexOutOfBoundsException bubbles uncaught, thus failing the whole constructor of the mapper without an option to adjust the A/B types manually.

from orika.

elaatifi avatar elaatifi commented on August 18, 2024

I just pushed a fix, can you please confirm if it fix your issue I also added a quick test.

from orika.

adammichalik avatar adammichalik commented on August 18, 2024

I checked 1.4.7-SNAPSHOT and it works fine with your fix. Thanks!

from orika.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.