Skip to content

Commit cb0ce53

Browse files
Inconsistent classfile encountered on annotated generic types (#4630)
* Fixes #4622
1 parent a6af724 commit cb0ce53

File tree

3 files changed

+133
-1
lines changed

3 files changed

+133
-1
lines changed

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2474,7 +2474,7 @@ public RecordComponentBinding[] setComponents(RecordComponentBinding[] component
24742474

24752475
for (RecordComponentBinding component : components) {
24762476
for (FieldBinding field : this.fields) {
2477-
if (CharOperation.equals(field.name, component.name) && field.type == null) { // field got built before record component resolution
2477+
if (CharOperation.equals(field.name, component.name)) { // field got built before record component resolution
24782478
field.type = component.type;
24792479
field.modifiers |= component.modifiers & ExtraCompilerModifiers.AccGenericSignature;
24802480
field.tagBits |= component.tagBits & (TagBits.AnnotationNullMASK | TagBits.AnnotationOwningMASK);

org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/IncrementalTests.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,4 +1781,58 @@ public Request(String id, T payload) {
17811781
env.removeProject(projectPath);
17821782
}
17831783

1784+
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/4622
1785+
// Inconsistent classfile encountered on annotated generic types
1786+
public void testIssue4622() throws JavaModelException {
1787+
IPath projectPath = env.addProject("Project", "19");
1788+
env.addExternalJars(projectPath, Util.getJavaClassLibs());
1789+
1790+
// remove old package fragment root so that names don't collide
1791+
env.removePackageFragmentRoot(projectPath, "");
1792+
1793+
IPath root = env.addPackageFragmentRoot(projectPath, "src");
1794+
env.setOutputFolder(projectPath, "bin");
1795+
1796+
env.addClass(root, "", "Record",
1797+
"""
1798+
import java.lang.annotation.Target;
1799+
1800+
public record Record(
1801+
Patch<@ValidUrlTemplate(value = UrlValidationType.AA, message = "{}") String> labelUrl) {
1802+
}
1803+
1804+
class Patch<T> {
1805+
public T field;
1806+
}
1807+
1808+
enum UrlValidationType {
1809+
AA, BB
1810+
}
1811+
1812+
@Target(java.lang.annotation.ElementType.TYPE_USE)
1813+
@interface ValidUrlTemplate {
1814+
UrlValidationType value();
1815+
String message();
1816+
}
1817+
""");
1818+
fullBuild(projectPath);
1819+
expectingNoProblems();
1820+
1821+
env.addClass(root, "", "Driver",
1822+
"""
1823+
public class Driver {
1824+
public Record r;
1825+
1826+
public static void main(String [] args) {
1827+
System.out.println("OK!");
1828+
}
1829+
}
1830+
""");
1831+
1832+
incrementalBuild(projectPath);
1833+
expectingNoProblems();
1834+
1835+
env.removeProject(projectPath);
1836+
}
1837+
17841838
}

org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11610,4 +11610,82 @@ enum RequiredMode {
1161011610
" )\n";
1161111611
verifyClassFile(expectedOutput, "test/Broken.class", ClassFileBytesDisassembler.SYSTEM);
1161211612
}
11613+
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/4622
11614+
// Inconsistent classfile encountered on annotated generic types
11615+
public void testIssue4622() throws Exception {
11616+
this.runConformTest(
11617+
new String[] {
11618+
"test/Record.java",
11619+
"""
11620+
package test;
11621+
11622+
import java.lang.annotation.Target;
11623+
11624+
public record Record(
11625+
Patch<@ValidUrlTemplate(value = UrlValidationType.AA, message = "{}") String> labelUrl) {
11626+
11627+
public static void main(String [] args) {
11628+
System.out.println("OK!");
11629+
}
11630+
}
11631+
11632+
class Patch<T> {
11633+
public T field;
11634+
}
11635+
11636+
enum UrlValidationType {
11637+
AA, BB
11638+
}
11639+
11640+
@Target(java.lang.annotation.ElementType.TYPE_USE)
11641+
@interface ValidUrlTemplate {
11642+
UrlValidationType value();
11643+
String message();
11644+
}
11645+
""",
11646+
},
11647+
"OK!");
11648+
String expectedOutput =
11649+
" // Field descriptor #6 Ltest/Patch;\n" +
11650+
" // Signature: Ltest/Patch<Ljava/lang/String;>;\n" +
11651+
" private final test.Patch labelUrl;\n" +
11652+
" RuntimeInvisibleTypeAnnotations: \n" +
11653+
" #10 @test.ValidUrlTemplate(\n" +
11654+
" #11 value=test.UrlValidationType.AA(enum type #12.#13)\n" +
11655+
" #14 message=\"{}\" (constant type)\n" +
11656+
" target type = 0x13 FIELD\n" +
11657+
" location = [TYPE_ARGUMENT(0)]\n" +
11658+
" )\n" +
11659+
" \n" +
11660+
" // Method descriptor #17 ([Ljava/lang/String;)V\n" +
11661+
" // Stack: 2, Locals: 1\n" +
11662+
" public static void main(java.lang.String[] args);\n" +
11663+
" 0 getstatic java.lang.System.out : java.io.PrintStream [19]\n" +
11664+
" 3 ldc <String \"OK!\"> [25]\n" +
11665+
" 5 invokevirtual java.io.PrintStream.println(java.lang.String) : void [27]\n" +
11666+
" 8 return\n" +
11667+
" Line numbers:\n" +
11668+
" [pc: 0, line: 9]\n" +
11669+
" [pc: 8, line: 10]\n" +
11670+
" Local variable table:\n" +
11671+
" [pc: 0, pc: 9] local: args index: 0 type: java.lang.String[]\n" +
11672+
" \n" +
11673+
" // Method descriptor #37 ()Ltest/Patch;\n" +
11674+
" // Signature: ()Ltest/Patch<Ljava/lang/String;>;\n" +
11675+
" // Stack: 1, Locals: 1\n" +
11676+
" public test.Patch labelUrl();\n" +
11677+
" 0 aload_0 [this]\n" +
11678+
" 1 getfield test.Record.labelUrl : test.Patch [39]\n" +
11679+
" 4 areturn\n" +
11680+
" Line numbers:\n" +
11681+
" [pc: 0, line: 6]\n" +
11682+
" RuntimeInvisibleTypeAnnotations: \n" +
11683+
" #10 @test.ValidUrlTemplate(\n" +
11684+
" #11 value=test.UrlValidationType.AA(enum type #12.#13)\n" +
11685+
" #14 message=\"{}\" (constant type)\n" +
11686+
" target type = 0x14 METHOD_RETURN\n" +
11687+
" location = [TYPE_ARGUMENT(0)]\n" +
11688+
" )";
11689+
verifyClassFile(expectedOutput, "test/Record.class", ClassFileBytesDisassembler.SYSTEM);
11690+
}
1161311691
}

0 commit comments

Comments
 (0)