Skip to content

Commit

Permalink
Add test and fix for badly compiled classes in Java 9-11.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Sep 6, 2024
1 parent b05c781 commit 7b1956a
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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 */
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {

Expand Down Expand Up @@ -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 */
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 7b1956a

Please sign in to comment.