google / closure-templates

A client- and server-side templating system that helps you dynamically build reusable HTML and UI elements

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error prone warnings in com.google.template.soy.base.internal.Identifier

Yannic opened this issue · comments

When building closure-templates with enabled errorprone checks (2.3.1), I get the following error in com.google.template.soy.base.internal.Identifier:

bazel-out/<redacted>/java/src/com/google/template/soy/base/internal/_javac/internal/libinternal_sourcegenfiles/com/google/template/soy/base/internal/AutoValue_Identifier.java:8: error: [Immutable] Class extends @Immutable type com.google.template.soy.base.internal.Identifier, but is not immutable: 'AutoValue_Identifier' has non-final field 'type'
  private transient volatile Identifier.Type type;
                                             ^
    (see https://errorprone.info/bugpattern/Immutable)
  Did you mean 'private final transient volatile Identifier.Type type;'?
Target //<redacted>/java/src/com/google/template/soy/base/internal:internal failed to build

https://github.com/closure-tools/closure-templates/blob/7acea66c65ee0d7b4ceab2d18247cf8d8f15a437/java/src/com/google/template/soy/base/internal/BUILD.bazel#L23

/cc @robfig @sgammon

Is this a bug in autovalue or is there a knob we can configure to generate this code?

I'm not sure if it's a false positive or an actual bug in autovalue or soy. Someone more familiar with autovalue will have to decide that. What I do know is that you can add @AutoValue.CopyAnnotations and @SuppressWarnings("Immutable") to suppress just this one error: https://errorprone.info/bugpattern/Immutable#suppression

I had a look at this again, and it seems like the cause for this error is that type() is lazily computed by annotating it as @Memoized. Per https://errorprone.info/bugpattern/Immutable, the fix is to add suppressions to the class.

Should I send a PR for this, or do you prefer fixing it yourself?

@Yannic, @iteriani has been pretty quick to respond to PRs lately. happy to file one too :)

@sgammon PRs need to be imported into Google, tested, submitted, and then pushed out. It's a simple 2 line change, so I'm not sure if it's worth the extra bit of effort if I submit the PR vs. submitting internally. Happy to do so if @iteriani wants me to.

I'm not a Googler. I'll send a PR for copy&pasting.

Fixed by 4f7808e