Skip to content

Commit b484417

Browse files
emspishakkevinb9n
authored andcommitted
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 #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
1 parent d9d66ad commit b484417

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

value/src/main/java/com/google/auto/value/extension/memoized/processor/MemoizeExtension.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,11 @@ public final class MemoizeExtension extends AutoValueExtension {
100100
private static final String AUTO_VALUE_NAME = AUTO_VALUE_PACKAGE_NAME + "AutoValue";
101101
private static final String COPY_ANNOTATIONS_NAME = AUTO_VALUE_NAME + ".CopyAnnotations";
102102

103+
// Maven is configured to shade (rewrite) com.google packages to prevent dependency conflicts.
104+
// Split up the package here with a call to concat to prevent Maven from finding and rewriting it,
105+
// so that this will be able to find the LazyInit annotation if it's on the classpath.
103106
private static final ClassName LAZY_INIT =
104-
ClassName.get("com.google.errorprone.annotations.concurrent", "LazyInit");
107+
ClassName.get("com".concat(".google.errorprone.annotations.concurrent"), "LazyInit");
105108

106109
private static final AnnotationSpec SUPPRESS_WARNINGS =
107110
AnnotationSpec.builder(SuppressWarnings.class).addMember("value", "$S", "Immutable").build();

0 commit comments

Comments
 (0)