mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#2263 Fix IndexOutOfBoundsException when resolving TypeVar to a Type
This commit is contained in:
parent
8f9df5b69b
commit
75f963adf6
@ -1159,7 +1159,12 @@ public class Type extends ModelElement implements Comparable<Type> {
|
||||
@Override
|
||||
public Type visitDeclared(DeclaredType t, Type parameterized) {
|
||||
if ( types.isAssignable( types.erasure( t ), types.erasure( parameterized.getTypeMirror() ) ) ) {
|
||||
// if same type, we can cast en assume number of type args are also the same
|
||||
// We can't assume that the type args are the same
|
||||
// e.g. List<T> is assignable to Object
|
||||
if ( t.getTypeArguments().size() != parameterized.getTypeParameters().size() ) {
|
||||
return super.visitDeclared( t, parameterized );
|
||||
}
|
||||
|
||||
for ( int i = 0; i < t.getTypeArguments().size(); i++ ) {
|
||||
Type result = visit( t.getTypeArguments().get( i ), parameterized.getTypeParameters().get( i ) );
|
||||
if ( result != null ) {
|
||||
|
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package org.mapstruct.ap.test.bugs._2263;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
|
||||
/**
|
||||
* @author Filip Hrisafov
|
||||
*/
|
||||
@Mapper
|
||||
public interface Erroneous2263Mapper {
|
||||
|
||||
Target map(Source source);
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package org.mapstruct.ap.test.bugs._2263;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mapstruct.ap.testutil.IssueKey;
|
||||
import org.mapstruct.ap.testutil.WithClasses;
|
||||
import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
|
||||
import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
|
||||
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
|
||||
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
|
||||
|
||||
/**
|
||||
* @author Filip Hrisafov
|
||||
*/
|
||||
@IssueKey("2263")
|
||||
@RunWith(AnnotationProcessorTestRunner.class)
|
||||
@WithClasses({
|
||||
Erroneous2263Mapper.class,
|
||||
Source.class,
|
||||
Target.class,
|
||||
})
|
||||
public class Issue2263Test {
|
||||
|
||||
@Test
|
||||
@ExpectedCompilationOutcome(value = CompilationResult.FAILED,
|
||||
diagnostics = {
|
||||
@Diagnostic(type = Erroneous2263Mapper.class,
|
||||
kind = javax.tools.Diagnostic.Kind.ERROR,
|
||||
line = 16,
|
||||
message = "Can't map property \"Object value\" to \"String value\". " +
|
||||
"Consider to declare/implement a mapping method: \"String map(Object value)\".")
|
||||
})
|
||||
public void shouldCorrectlyReportUnmappableTargetObject() {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package org.mapstruct.ap.test.bugs._2263;
|
||||
|
||||
/**
|
||||
* @author Filip Hrisafov
|
||||
*/
|
||||
public class Source {
|
||||
|
||||
private final Object value;
|
||||
|
||||
public Source(Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package org.mapstruct.ap.test.bugs._2263;
|
||||
|
||||
/**
|
||||
* @author Filip Hrisafov
|
||||
*/
|
||||
public class Target {
|
||||
|
||||
private final String value;
|
||||
|
||||
public Target(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user