Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2474,7 +2474,7 @@ public RecordComponentBinding[] setComponents(RecordComponentBinding[] component

for (RecordComponentBinding component : components) {
for (FieldBinding field : this.fields) {
if (CharOperation.equals(field.name, component.name) && field.type == null) { // field got built before record component resolution
if (CharOperation.equals(field.name, component.name)) { // field got built before record component resolution
field.type = component.type;
field.modifiers |= component.modifiers & ExtraCompilerModifiers.AccGenericSignature;
field.tagBits |= component.tagBits & (TagBits.AnnotationNullMASK | TagBits.AnnotationOwningMASK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1781,4 +1781,58 @@ public Request(String id, T payload) {
env.removeProject(projectPath);
}

// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/4622
// Inconsistent classfile encountered on annotated generic types
public void testIssue4622() throws JavaModelException {
IPath projectPath = env.addProject("Project", "19");
env.addExternalJars(projectPath, Util.getJavaClassLibs());

// remove old package fragment root so that names don't collide
env.removePackageFragmentRoot(projectPath, "");

IPath root = env.addPackageFragmentRoot(projectPath, "src");
env.setOutputFolder(projectPath, "bin");

env.addClass(root, "", "Record",
"""
import java.lang.annotation.Target;

public record Record(
Patch<@ValidUrlTemplate(value = UrlValidationType.AA, message = "{}") String> labelUrl) {
}

class Patch<T> {
public T field;
}

enum UrlValidationType {
AA, BB
}

@Target(java.lang.annotation.ElementType.TYPE_USE)
@interface ValidUrlTemplate {
UrlValidationType value();
String message();
}
""");
fullBuild(projectPath);
expectingNoProblems();

env.addClass(root, "", "Driver",
"""
public class Driver {
public Record r;

public static void main(String [] args) {
System.out.println("OK!");
}
}
""");

incrementalBuild(projectPath);
expectingNoProblems();

env.removeProject(projectPath);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11610,4 +11610,82 @@ enum RequiredMode {
" )\n";
verifyClassFile(expectedOutput, "test/Broken.class", ClassFileBytesDisassembler.SYSTEM);
}
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/4622
// Inconsistent classfile encountered on annotated generic types
public void testIssue4622() throws Exception {
this.runConformTest(
new String[] {
"test/Record.java",
"""
package test;

import java.lang.annotation.Target;

public record Record(
Patch<@ValidUrlTemplate(value = UrlValidationType.AA, message = "{}") String> labelUrl) {

public static void main(String [] args) {
System.out.println("OK!");
}
}

class Patch<T> {
public T field;
}

enum UrlValidationType {
AA, BB
}

@Target(java.lang.annotation.ElementType.TYPE_USE)
@interface ValidUrlTemplate {
UrlValidationType value();
String message();
}
""",
},
"OK!");
String expectedOutput =
" // Field descriptor #6 Ltest/Patch;\n" +
" // Signature: Ltest/Patch<Ljava/lang/String;>;\n" +
" private final test.Patch labelUrl;\n" +
" RuntimeInvisibleTypeAnnotations: \n" +
" #10 @test.ValidUrlTemplate(\n" +
" #11 value=test.UrlValidationType.AA(enum type #12.#13)\n" +
" #14 message=\"{}\" (constant type)\n" +
" target type = 0x13 FIELD\n" +
" location = [TYPE_ARGUMENT(0)]\n" +
" )\n" +
" \n" +
" // Method descriptor #17 ([Ljava/lang/String;)V\n" +
" // Stack: 2, Locals: 1\n" +
" public static void main(java.lang.String[] args);\n" +
" 0 getstatic java.lang.System.out : java.io.PrintStream [19]\n" +
" 3 ldc <String \"OK!\"> [25]\n" +
" 5 invokevirtual java.io.PrintStream.println(java.lang.String) : void [27]\n" +
" 8 return\n" +
" Line numbers:\n" +
" [pc: 0, line: 9]\n" +
" [pc: 8, line: 10]\n" +
" Local variable table:\n" +
" [pc: 0, pc: 9] local: args index: 0 type: java.lang.String[]\n" +
" \n" +
" // Method descriptor #37 ()Ltest/Patch;\n" +
" // Signature: ()Ltest/Patch<Ljava/lang/String;>;\n" +
" // Stack: 1, Locals: 1\n" +
" public test.Patch labelUrl();\n" +
" 0 aload_0 [this]\n" +
" 1 getfield test.Record.labelUrl : test.Patch [39]\n" +
" 4 areturn\n" +
" Line numbers:\n" +
" [pc: 0, line: 6]\n" +
" RuntimeInvisibleTypeAnnotations: \n" +
" #10 @test.ValidUrlTemplate(\n" +
" #11 value=test.UrlValidationType.AA(enum type #12.#13)\n" +
" #14 message=\"{}\" (constant type)\n" +
" target type = 0x14 METHOD_RETURN\n" +
" location = [TYPE_ARGUMENT(0)]\n" +
" )";
verifyClassFile(expectedOutput, "test/Record.class", ClassFileBytesDisassembler.SYSTEM);
}
}
Loading