[Bug] Annotation processor generated duplicated classes from dependency that also used autovalue
- Dominant language
- Java
- Stars
- 10.6k
- Forks
- 1.2k
- Avg merge
- 6h 32m
- Merged PRs (30d)
- 13
Description
My Maven project is a java library, and it has another java library dependency, both my project and that dependency are under same package name.
Here is a minimum example.
My project has a single source file:
```java
package org.apache.beam.sdk.io.gcp.spanner;
import com.google.auto.value.AutoValue;
@AutoValue
public abstract class DuplicateSpannerConfig {
@AutoValue.Builder
public abstract static class Builder {
public abstract DuplicateSpannerConfig build();
}
}
```
and declared a dependency
```
1.10.4
2.54.0
3.11.0
11
11
com.google.auto.value
auto-value
${autovalue.version}
provided
com.google.auto.value
auto-value-annotations
${autovalue.version}
org.apache.beam
beam-sdks-java-io-google-cloud-platform
${beam.version}
```
Run `mvn clean compile`
Expected: only AutoValue_DuplicateSpannerConfig in `target/classes/org/apache/beam/sdk/io/gcp/spanner/` and `target/classes`
Actual: there are many AutoValue_* classes, seemingly regenerated from binaries in `beam-sdks-java-io-google-cloud-platform` in `target/classes/org/apache/beam/sdk/io/gcp/spanner/`.
Also, it seems there are specific conditions to trigger this bug:
- If I my the `@AutoValue` class into an inner class, only my class was processed.
- I also setup a same Gradle project, instead of using Maven, it works fine
The example is also available at https://github.com/Abacn/codesnippets/tree/master/AutoValueTest .
This was found by https://github.com/GoogleCloudPlatform/DataflowTemplates/actions/runs/8268070883 and reproduced locally. It is problematic for that project because the duplicated AutoValue_* classes does not handle nullable members correctly. For example, even though the decompiled dependency jar shows the `@AutoValue` abstract class has nullable members, e.g.
```
abstract @UnknownKeyFor @NonNull @Initialized Builder setCredentials(@UnknownKeyFor @NonNull @Initialized ValueProvider<@UnknownKeyFor @NonNull @Initialized Credentials> credentials);
```
and the AutoValue class in the dependency jar correctly marked it nullable
```
private @Nullable ValueProvider credentials;
```
nullable annotations get lost in the duplicate (generated) AutoValue class, unless my project duplicate the sources of the dependency jar (that is what currently did in DataflowTemplates/v1/.../gcp/spanner
Contributor guide
Assessment
This issue has not been assessed yet.