Skip to content

Optional "wrapping" pattern broken with 1.5.0.Beta #2673

@kenwang-coursera

Description

@kenwang-coursera
  • Is this an issue (and hence not a question)?

The following pattern worked as a way to map from Optional to non Optional:

    default <T> Optional<T> wrap(T value) {
        return Optional.ofNullable(value);
    }

    default <T> T unwrap(Optional<T> value) {
        return value.orElse(null);
    }

However, with 1.5.0.Beta compilation seems to fail on an unrelated field.

For example, my classes are:

public record FromClass(int a, Optional<String> b) {}

public record ToClass(int a, String b) {}

During compilation I get:

error: Internal error in the mapping processor: java.lang.IllegalArgumentException: int     at jdk.compiler/com.sun.tools.javac.model.JavacTypes.getDeclaredType0(JavacTypes.java:272)      at jdk.compiler/com.sun.tools.javac.model.JavacTypes.getDeclaredType(JavacTypes.java:241)       at org.mapstruct.ap.internal.util.AbstractTypeUtilsDecorator.getDeclaredType(AbstractTypeUtilsDecorator.java:119)       at org.mapstruct.ap.internal.model.source.MethodMatcher$GenericAnalyser.resolve(MethodMatcher.java:381)         at org.mapstruct.ap.internal.model.source.MethodMatcher$GenericAnalyser.lineUp(MethodMatcher.java:174)          at org.mapstruct.ap.internal.model.source.MethodMatcher$GenericAnalyser.access$000(MethodMatcher.java:110)      at org.mapstruct.ap.internal.model.source.MethodMatcher.matches(MethodMatcher.java:71)          at org.mapstruct.ap.internal.model.source.SourceMethod.matches(SourceMethod.java:497)   at org.mapstruct.ap.internal.model.source.selector.TypeSelector.lambda$getMatchingParameterBinding$0(TypeSelector.java:164)     at java.base/java.util.ArrayList.removeIf(ArrayList.java:1672)
...

If I explicitly ignore the mappings for the unrelated field a then the compilation works as expected.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions