diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/description/type/TypeDescription.java b/byte-buddy-dep/src/main/java/net/bytebuddy/description/type/TypeDescription.java index a3ec02597c..ddfd1ff99b 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/description/type/TypeDescription.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/description/type/TypeDescription.java @@ -1903,9 +1903,14 @@ abstract class Substitutor implements Visitor { */ public Generic onParameterizedType(Generic parameterizedType) { Generic ownerType = parameterizedType.getOwnerType(); - List typeArguments = new ArrayList(parameterizedType.getTypeArguments().size()); - for (Generic typeArgument : parameterizedType.getTypeArguments()) { - typeArguments.add(typeArgument.accept(this)); + List typeArguments; + if (TypeDescription.AbstractBase.RAW_TYPES) { + typeArguments = Collections.emptyList(); + } else { + typeArguments = new ArrayList<>(parameterizedType.getTypeArguments().size()); + for (Generic typeArgument : parameterizedType.getTypeArguments()) { + typeArguments.add(typeArgument.accept(this)); + } } return new OfParameterizedType.Latent(parameterizedType.asRawType().accept(this).asErasure(), ownerType == null diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/description/type/TypeDescriptionGenericVisitorSubstitutorForTypeVariableBindingWithRawTypesTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/description/type/TypeDescriptionGenericVisitorSubstitutorForTypeVariableBindingWithRawTypesTest.java new file mode 100644 index 0000000000..efae67faf0 --- /dev/null +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/description/type/TypeDescriptionGenericVisitorSubstitutorForTypeVariableBindingWithRawTypesTest.java @@ -0,0 +1,30 @@ +package net.bytebuddy.description.type; + +import org.hamcrest.CoreMatchers; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +public class TypeDescriptionGenericVisitorSubstitutorForTypeVariableBindingWithRawTypesTest { + + @Mock + private TypeDescription.Generic visitedType, parameterizedType, rawType; + + @Test + @SuppressWarnings("unchecked") + public void testParameterizedTypeWithRawTypes() throws Exception { + System.setProperty(TypeDefinition.RAW_TYPES_PROPERTY, "true"); + MockitoAnnotations.initMocks(this); + + when(parameterizedType.asRawType()).thenReturn(rawType); + when(rawType.accept(any(TypeDescription.Generic.Visitor.class))).thenReturn(rawType); + when(parameterizedType.getTypeArguments()).thenReturn(new TypeList.Generic.Explicit(TypeDescription.Generic.OfNonGenericType.ForLoadedType.of(Object.class))); + TypeDescription.Generic result = new TypeDescription.Generic.Visitor.Substitutor.ForTypeVariableBinding(visitedType).onParameterizedType(parameterizedType); + + assertThat(result.getTypeArguments(), CoreMatchers.is(new TypeList.Generic.Explicit())); + } +}