diff options
author | Liam Miller-Cushon <cushon@google.com> | 2022-02-10 09:52:57 -0800 |
---|---|---|
committer | Javac Team <javac-team+copybara@google.com> | 2022-02-10 09:53:49 -0800 |
commit | fcc8a28e02dc65c04e3c54646fc9cf8eea035101 (patch) | |
tree | 26c7549158e238a2ae6dd822558a80e7e87840e2 | |
parent | 2e51367e85ef98366640a15e012717f43aff2068 (diff) | |
download | turbine-fcc8a28e02dc65c04e3c54646fc9cf8eea035101.tar.gz |
Don't crash on missing annotation arguments
If turbine creates annotation proxies for annotations missing required elements,
they crash if the element is accessed. This should be an unrecoverable error
that aborts annotation processing.
PiperOrigin-RevId: 427775703
3 files changed, 29 insertions, 7 deletions
diff --git a/java/com/google/turbine/binder/ConstEvaluator.java b/java/com/google/turbine/binder/ConstEvaluator.java index d26667d..771e87f 100644 --- a/java/com/google/turbine/binder/ConstEvaluator.java +++ b/java/com/google/turbine/binder/ConstEvaluator.java @@ -1269,7 +1269,8 @@ public strictfp class ConstEvaluator { } for (MethodInfo methodInfo : template.values()) { if (!methodInfo.hasDefaultValue()) { - log.error(info.tree().position(), ErrorKind.MISSING_ANNOTATION_ARGUMENT, methodInfo.name()); + throw error( + info.tree().position(), ErrorKind.MISSING_ANNOTATION_ARGUMENT, methodInfo.name()); } } return info.withValues(ImmutableMap.copyOf(values)); diff --git a/javatests/com/google/turbine/binder/BinderErrorTest.java b/javatests/com/google/turbine/binder/BinderErrorTest.java index 83a0e3f..6766470 100644 --- a/javatests/com/google/turbine/binder/BinderErrorTest.java +++ b/javatests/com/google/turbine/binder/BinderErrorTest.java @@ -771,12 +771,6 @@ public class BinderErrorTest { "<>:3: error: missing required annotation argument: value", "@Retention", "^", - "<>:4: error: missing required annotation argument: value", - "@Retention", - "^", - "<>:3: error: java.lang.annotation.Retention is not @Repeatable", - "@Retention", - "^", }, }, { diff --git a/javatests/com/google/turbine/processing/ProcessingIntegrationTest.java b/javatests/com/google/turbine/processing/ProcessingIntegrationTest.java index 39b36e1..cf84ec5 100644 --- a/javatests/com/google/turbine/processing/ProcessingIntegrationTest.java +++ b/javatests/com/google/turbine/processing/ProcessingIntegrationTest.java @@ -676,6 +676,33 @@ public class ProcessingIntegrationTest { "METHOD y()"); } + @Test + public void missingElementValue() { + ImmutableList<Tree.CompUnit> units = + parseUnit( + "=== T.java ===", // + "import java.lang.annotation.Retention;", + "@Retention() @interface T {}"); + TurbineError e = + assertThrows( + TurbineError.class, + () -> + Binder.bind( + units, + ClassPathBinder.bindClasspath(ImmutableList.of()), + ProcessorInfo.create( + // missing annotation arguments are not a recoverable error, annotation + // processing shouldn't happen + ImmutableList.of(new CrashingProcessor()), + getClass().getClassLoader(), + ImmutableMap.of(), + SourceVersion.latestSupported()), + TestClassPaths.TURBINE_BOOTCLASSPATH, + Optional.empty())); + assertThat(e.diagnostics().stream().map(d -> d.message())) + .containsExactly("missing required annotation argument: value"); + } + private static ImmutableList<Tree.CompUnit> parseUnit(String... lines) { return IntegrationTestSupport.TestInput.parse(Joiner.on('\n').join(lines)) .sources |