From b48441776bb1eefe120dd4de5711e50209f46917 Mon Sep 17 00:00:00 2001 From: spishak Date: Wed, 8 Jul 2020 08:50:55 -0700 Subject: 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 --- .../auto/value/extension/memoized/processor/MemoizeExtension.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'value/src/main') 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(); -- cgit v1.2.3