Skip to content

Commit

Permalink
Don't read <clinit>s from class files
Browse files Browse the repository at this point in the history
This was causing an error when checking required annotation elements for
annotations with `<clinit>`s read from bytecode:

```
error: missing required annotation argument: <clinit>
@foo
```

bazelbuild/bazel#13144

PiperOrigin-RevId: 360553027
  • Loading branch information
cushon authored and Javac Team committed Mar 3, 2021
1 parent aabe1f4 commit 617a8f6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@ public ImmutableList<MethodInfo> get() {
ImmutableList.Builder<MethodInfo> methods = ImmutableList.builder();
int idx = 0;
for (ClassFile.MethodInfo m : classFile.get().methods()) {
if (m.name().equals("<clinit>")) {
// Don't bother reading class initializers, which we don't need
continue;
}
methods.add(bindMethod(idx++, m));
}
return methods.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ public static Iterable<Object[]> parameters() {
"field_anno.test",
"annotation_bool_default.test",
"annotation_class_default.test",
"annotation_clinit.test",
"annotation_declaration.test",
"annotation_enum_default.test",
"annotations_default.test",
Expand Down
18 changes: 18 additions & 0 deletions javatests/com/google/turbine/lower/testdata/annotation_clinit.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
%%% pkg/Anno.java %%%
package pkg;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
public @interface Anno {
String CONSTANT = Anno.class.toString();

String value() default "";
}

=== pkg/T.java ===
package pkg;

@Anno
class T {}

0 comments on commit 617a8f6

Please sign in to comment.