LANG-1371: Fix TypeUtils.parameterize to work correctly with narrower-typed varargs array (closes #307)
This commit is contained in:
parent
bfb43d3fe2
commit
d8ec011d77
|
@ -157,7 +157,7 @@ public class TypeUtils {
|
|||
private ParameterizedTypeImpl(final Class<?> raw, final Type useOwner, final Type[] typeArguments) {
|
||||
this.raw = raw;
|
||||
this.useOwner = useOwner;
|
||||
this.typeArguments = typeArguments.clone();
|
||||
this.typeArguments = Arrays.copyOf(typeArguments, typeArguments.length, Type[].class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -34,6 +34,7 @@ import java.net.URI;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -690,6 +691,15 @@ public class TypeUtilsTest<B> {
|
|||
assertEquals("java.lang.Comparable<java.lang.String>", stringComparableType.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameterizeNarrowerTypeArray() {
|
||||
final TypeVariable<?>[] variables = ArrayList.class.getTypeParameters();
|
||||
final ParameterizedType parameterizedType = TypeUtils.parameterize(ArrayList.class, variables);
|
||||
final Map<TypeVariable<?>, Type> mapping = Collections.<TypeVariable<?>, Type>singletonMap(variables[0], String.class);
|
||||
final Type unrolled = TypeUtils.unrollVariables(mapping, parameterizedType);
|
||||
assertEquals(TypeUtils.parameterize(ArrayList.class, String.class), unrolled);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameterizeWithOwner() throws Exception {
|
||||
final Type owner = TypeUtils.parameterize(TypeUtilsTest.class, String.class);
|
||||
|
|
Loading…
Reference in New Issue