404-not-find / orika

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

Filter dest value + nested properties = NPE #189

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hi

After upgrade from 1.4.4 to 1.4.5 my mappers began to spit NPE's. The problem 
lies in additional dest parameter for Filter confronted with nested properties. 
Consider generated code for simple exemplary mapping such as:

factory.registerClassMap(factory.classMap(A.class, B.class).field("value", 
"c.value"));
factory.registerFilter(new NullFilter<Integer, Integer>());

Here's the generated mapper code:

    if (!(((java.lang.Integer) source.getValue()) == null)) {

        if ((((ma.glasnost.orika.bug.C) destination.getC()) == null)) {

            destination
                .setC(((ma.glasnost.orika.bug.C) ((ma.glasnost.orika.BoundMapperFacade) usedMapperFacades[0])
                    .newObject(((java.lang.Integer) source.getValue()), mappingContext)));
        }
    }

    // If source.getValue() returns null the call to shouldMap method will result in NPE. 
    //  (destination.getC().getValue()), getC() returns null.

    if (((ma.glasnost.orika.Filter) usedFilters[0]).shouldMap(((ma.glasnost.orika.metadata.Type) usedTypes[0]),
        "value", ((java.lang.Integer) source.getValue()), ((ma.glasnost.orika.metadata.Type) usedTypes[0]),
        "c.value", ((java.lang.Integer) ((ma.glasnost.orika.bug.C) destination.getC()).getValue()),
    mappingContext)) {
        if (!(((java.lang.Integer) source.getValue()) == null)) {

            if (!(((java.lang.Integer) source.getValue()) == null)) {

                if ((((ma.glasnost.orika.bug.C) destination.getC()) == null)) {

                    destination
                        .setC(((ma.glasnost.orika.bug.C) ((ma.glasnost.orika.BoundMapperFacade) usedMapperFacades[0])
                            .newObject(((java.lang.Integer) source.getValue()), mappingContext)));
                }
            }

            ((ma.glasnost.orika.bug.C) destination.getC()).setValue(((java.lang.Integer) source.getValue()));
        } else if (!(((ma.glasnost.orika.bug.C) destination.getC()) == null)) {
            ((ma.glasnost.orika.bug.C) destination.getC()).setValue(null);
        }

It's obvious that mapper should protect the input for shouldMap method. I had 
to fallback to 1.4.4 because of this issue. I tried with 1.4.6-SNAPSHOT but it 
seems that this issue hasn't been addressed yet.

best regards,
Piotr

Original issue reported on code.google.com by flove...@gmail.com on 22 Jan 2015 at 10:43

Attachments: