diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/pool/TypePool.java b/byte-buddy-dep/src/main/java/net/bytebuddy/pool/TypePool.java index 43f25592dfb..805199971fa 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/pool/TypePool.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/pool/TypePool.java @@ -8852,6 +8852,7 @@ public AnnotationVisitor visitTypeAnnotation(int rawTypeReference, TypePath type typePath, receiverTypeAnnotationTokens); break; + case TypeReference.CLASS_EXTENDS: // Emitted by mistake by javac for type variables in Java 9-11. case TypeReference.FIELD: // Emitted by mistake by javac for records in Java 14. return null; default: diff --git a/byte-buddy-dep/src/test/java-11/net/bytebuddy/test/precompiled/v11/ClassExtendsTypeReference.java b/byte-buddy-dep/src/test/java-11/net/bytebuddy/test/precompiled/v11/ClassExtendsTypeReference.java new file mode 100644 index 00000000000..789837add2b --- /dev/null +++ b/byte-buddy-dep/src/test/java-11/net/bytebuddy/test/precompiled/v11/ClassExtendsTypeReference.java @@ -0,0 +1,22 @@ +package net.bytebuddy.test.precompiled.v11; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.util.ArrayList; + +public class ClassExtendsTypeReference { + + @Retention(RetentionPolicy.RUNTIME) + @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) + public @interface TypeAnnotation { + /* empty */ + } + + public Object foo() { + return new ArrayList<@TypeAnnotation Object>() { + /* empty */ + }; + } +} diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/description/type/AbstractTypeDescriptionTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/description/type/AbstractTypeDescriptionTest.java index 583f284394e..6fa15f28103 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/description/type/AbstractTypeDescriptionTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/description/type/AbstractTypeDescriptionTest.java @@ -13,6 +13,7 @@ import net.bytebuddy.dynamic.loading.ClassLoadingStrategy; import net.bytebuddy.dynamic.loading.PackageDefinitionStrategy; import net.bytebuddy.implementation.bytecode.StackSize; +import net.bytebuddy.pool.TypePool; import net.bytebuddy.test.packaging.SimpleType; import net.bytebuddy.test.scope.EnclosingType; import net.bytebuddy.test.utility.JavaVersionRule; @@ -44,8 +45,7 @@ import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; public abstract class AbstractTypeDescriptionTest extends AbstractTypeDescriptionGenericVariableDefiningTest { @@ -915,6 +915,14 @@ public void testRecordComponentsConstructorParameter() throws Exception { assertThat(parameterDescription.getType().getTypeArguments().getOnly().getDeclaredAnnotations().getOnly().prepare(typeAnnotation).getValue(value).resolve(), is((Object) 84)); } + @Test + @JavaVersionRule.Enforce(11) + public void testIllegalReferenceOnTypeVariableOnOutdatedJdks() throws Exception { + Class type = Class.forName("net.bytebuddy.test.precompiled.v11.ClassExtendsTypeReference"); + TypeDescription description = describe(type); + assertThat(description.getDeclaredMethods().filter(isMethod()).getOnly().getTypeVariables().size(), is(0)); + } + private Class inMethodClass() { class InMethod { /* empty */ diff --git a/byte-buddy-dep/src/test/precompiled-11/net/bytebuddy/test/precompiled/v11/ClassExtendsTypeReference$1.class b/byte-buddy-dep/src/test/precompiled-11/net/bytebuddy/test/precompiled/v11/ClassExtendsTypeReference$1.class new file mode 100644 index 00000000000..f8afbcd9e10 Binary files /dev/null and b/byte-buddy-dep/src/test/precompiled-11/net/bytebuddy/test/precompiled/v11/ClassExtendsTypeReference$1.class differ diff --git a/byte-buddy-dep/src/test/precompiled-11/net/bytebuddy/test/precompiled/v11/ClassExtendsTypeReference$TypeAnnotation.class b/byte-buddy-dep/src/test/precompiled-11/net/bytebuddy/test/precompiled/v11/ClassExtendsTypeReference$TypeAnnotation.class new file mode 100644 index 00000000000..402dea72de2 Binary files /dev/null and b/byte-buddy-dep/src/test/precompiled-11/net/bytebuddy/test/precompiled/v11/ClassExtendsTypeReference$TypeAnnotation.class differ diff --git a/byte-buddy-dep/src/test/precompiled-11/net/bytebuddy/test/precompiled/v11/ClassExtendsTypeReference.class b/byte-buddy-dep/src/test/precompiled-11/net/bytebuddy/test/precompiled/v11/ClassExtendsTypeReference.class new file mode 100644 index 00000000000..ac07bbd6ab7 Binary files /dev/null and b/byte-buddy-dep/src/test/precompiled-11/net/bytebuddy/test/precompiled/v11/ClassExtendsTypeReference.class differ diff --git a/byte-buddy-dep/src/test/precompiled-11/net/bytebuddy/test/precompiled/v11/DynamicConstantBootstrap$Other.class b/byte-buddy-dep/src/test/precompiled-11/net/bytebuddy/test/precompiled/v11/DynamicConstantBootstrap$Other.class index 80fbb910382..71115ab0900 100644 Binary files a/byte-buddy-dep/src/test/precompiled-11/net/bytebuddy/test/precompiled/v11/DynamicConstantBootstrap$Other.class and b/byte-buddy-dep/src/test/precompiled-11/net/bytebuddy/test/precompiled/v11/DynamicConstantBootstrap$Other.class differ diff --git a/byte-buddy-dep/src/test/precompiled-11/net/bytebuddy/test/precompiled/v11/DynamicConstantBootstrap.class b/byte-buddy-dep/src/test/precompiled-11/net/bytebuddy/test/precompiled/v11/DynamicConstantBootstrap.class index cd2a55071aa..48c6c6ea624 100644 Binary files a/byte-buddy-dep/src/test/precompiled-11/net/bytebuddy/test/precompiled/v11/DynamicConstantBootstrap.class and b/byte-buddy-dep/src/test/precompiled-11/net/bytebuddy/test/precompiled/v11/DynamicConstantBootstrap.class differ