From 617a8f61b47d31f710386331b4380ba3c9c93872 Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Tue, 2 Mar 2021 17:33:27 -0800 Subject: [PATCH] Don't read ``s from class files This was causing an error when checking required annotation elements for annotations with ``s read from bytecode: ``` error: missing required annotation argument: @Foo ``` https://github.com/bazelbuild/bazel/issues/13144 PiperOrigin-RevId: 360553027 --- .../binder/bytecode/BytecodeBoundClass.java | 4 ++++ .../turbine/lower/LowerIntegrationTest.java | 1 + .../lower/testdata/annotation_clinit.test | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 javatests/com/google/turbine/lower/testdata/annotation_clinit.test diff --git a/java/com/google/turbine/binder/bytecode/BytecodeBoundClass.java b/java/com/google/turbine/binder/bytecode/BytecodeBoundClass.java index d337181a..8939780d 100644 --- a/java/com/google/turbine/binder/bytecode/BytecodeBoundClass.java +++ b/java/com/google/turbine/binder/bytecode/BytecodeBoundClass.java @@ -379,6 +379,10 @@ public ImmutableList get() { ImmutableList.Builder methods = ImmutableList.builder(); int idx = 0; for (ClassFile.MethodInfo m : classFile.get().methods()) { + if (m.name().equals("")) { + // Don't bother reading class initializers, which we don't need + continue; + } methods.add(bindMethod(idx++, m)); } return methods.build(); diff --git a/javatests/com/google/turbine/lower/LowerIntegrationTest.java b/javatests/com/google/turbine/lower/LowerIntegrationTest.java index 85c3450a..0bc883d1 100644 --- a/javatests/com/google/turbine/lower/LowerIntegrationTest.java +++ b/javatests/com/google/turbine/lower/LowerIntegrationTest.java @@ -180,6 +180,7 @@ public static Iterable 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", diff --git a/javatests/com/google/turbine/lower/testdata/annotation_clinit.test b/javatests/com/google/turbine/lower/testdata/annotation_clinit.test new file mode 100644 index 00000000..7419ed65 --- /dev/null +++ b/javatests/com/google/turbine/lower/testdata/annotation_clinit.test @@ -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 {}