aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorspishak <spishak@google.com>2020-07-08 08:50:55 -0700
committerkevinb9n <kevinb@google.com>2020-07-08 15:13:27 -0700
commitb48441776bb1eefe120dd4de5711e50209f46917 (patch)
tree608f05b3ad736d258c62603af3dbc136b24108f4
parentd9d66ad60b4a09f74b7a9822fb347a1dbedf28f4 (diff)
downloadauto-b48441776bb1eefe120dd4de5711e50209f46917.tar.gz
Stop the LazyInit annotation from getting shaded by Maven, so that AutoValue can find it on the classpath.
The @LazyInit annotation is added if it's found on the classpath (https://github.com/google/auto/blob/da84ef1fae38f2d72901c2b95674271e89600f28/value/src/main/java/com/google/auto/value/extension/memoized/processor/MemoizeExtension.java#L577) but shading rewrites the package at https://github.com/google/auto/blob/da84ef1fae38f2d72901c2b95674271e89600f28/value/src/main/java/com/google/auto/value/extension/memoized/processor/MemoizeExtension.java#L104 from "com.google.errorprone.annotations.concurrent" to "autovalue.shaded.com.google$.errorprone.annotations.$concurrent" (you can verify this by disassembling the bytecode for MemoizeExtension.class in the release JAR). This means that even with the Error Prone annotations on the classpath, it won't be able to find the LazyInit annotation. Splitting up the package with a call to String#concat means Maven will no longer rewrite it, so AutoValue will be able to find the LazyInit annotation on the classpath if it's there. Fixes https://github.com/google/auto/issues/427 RELNOTES=Stop the LazyInit annotation from getting shaded by Maven, so that AutoValue can find it on the classpath. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=320196133
-rw-r--r--value/src/main/java/com/google/auto/value/extension/memoized/processor/MemoizeExtension.java5
1 files changed, 4 insertions, 1 deletions
diff --git a/value/src/main/java/com/google/auto/value/extension/memoized/processor/MemoizeExtension.java b/value/src/main/java/com/google/auto/value/extension/memoized/processor/MemoizeExtension.java
index db2f2212..0ca46bde 100644
--- a/value/src/main/java/com/google/auto/value/extension/memoized/processor/MemoizeExtension.java
+++ b/value/src/main/java/com/google/auto/value/extension/memoized/processor/MemoizeExtension.java
@@ -100,8 +100,11 @@ public final class MemoizeExtension extends AutoValueExtension {
private static final String AUTO_VALUE_NAME = AUTO_VALUE_PACKAGE_NAME + "AutoValue";
private static final String COPY_ANNOTATIONS_NAME = AUTO_VALUE_NAME + ".CopyAnnotations";
+ // Maven is configured to shade (rewrite) com.google packages to prevent dependency conflicts.
+ // Split up the package here with a call to concat to prevent Maven from finding and rewriting it,
+ // so that this will be able to find the LazyInit annotation if it's on the classpath.
private static final ClassName LAZY_INIT =
- ClassName.get("com.google.errorprone.annotations.concurrent", "LazyInit");
+ ClassName.get("com".concat(".google.errorprone.annotations.concurrent"), "LazyInit");
private static final AnnotationSpec SUPPRESS_WARNINGS =
AnnotationSpec.builder(SuppressWarnings.class).addMember("value", "$S", "Immutable").build();