question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

add a @Generated and @Nullable annotations

See original GitHub issue

static analysis tools will now (often) recognize these by name alone, so it would be ideal if Immutables provided them. Example of problems

/Users/calebcushing/IdeaProjects/ppm/scaf/build/generated/sources/annotationProcessor/java/main/com/xenoterracide/scaf/ImmutableSkeletonConfiguration.java:135: error: [UnusedVariable] The parameter 'synthetic' is never read.
  private boolean equalTo(int synthetic, ImmutableSkeletonConfiguration another) {
                              ^
    (see https://errorprone.info/bugpattern/UnusedVariable)
  Did you mean '&& equalTo((ImmutableSkeletonConfiguration) another);'?
/Users/calebcushing/IdeaProjects/ppm/scaf/build/generated/sources/annotationProcessor/java/main/com/xenoterracide/scaf/ImmutableSkeletonConfiguration.java:148: error: [Var] Non-constant variable missing @Var annotation
    int h = 5381;
        ^
    (see https://errorprone.info/bugpattern/Var)
  Did you mean '@Var int h = 5381;'?
/Users/calebcushing/IdeaProjects/ppm/scaf/build/generated/sources/annotationProcessor/java/main/com/xenoterracide/scaf/ImmutableSkeletonConfiguration.java:179: error: [NullAway] @NonNull field ImmutableSkeletonConfiguration$Json.templateSourceType not initialized
    Application.SourceType templateSourceType;
                           ^
    (see http://t.uber.com/nullaway )
/Users/calebcushing/IdeaProjects/ppm/scaf/build/generated/sources/annotationProcessor/java/main/com/xenoterracide/scaf/ImmutableSkeletonConfiguration.java:180: error: [NullAway] @NonNull field ImmutableSkeletonConfiguration$Json.source not initialized
    String source;
           ^
    (see http://t.uber.com/nullaway )
/Users/calebcushing/IdeaProjects/ppm/scaf/build/generated/sources/annotationProcessor/java/main/com/xenoterracide/scaf/ImmutableSkeletonConfiguration.java:181: error: [NullAway] @NonNull field ImmutableSkeletonConfiguration$Json.destination not initialized
    String destination;
           ^
    (see http://t.uber.com/nullaway )
/Users/calebcushing/IdeaProjects/ppm/scaf/build/generated/sources/annotationProcessor/java/main/com/xenoterracide/scaf/ImmutableSkeletonConfiguration.java:182: error: [NullAway] @NonNull field ImmutableSkeletonConfiguration$Json.after not initialized
    Pattern after;
            ^
    (see http://t.uber.com/nullaway )
/Users/calebcushing/IdeaProjects/ppm/scaf/build/generated/sources/annotationProcessor/java/main/com/xenoterracide/scaf/ImmutableSkeletonConfiguration.java:285: error: [NullAway] initializer method does not guarantee @NonNull fields templateSourceType (line 280), source (line 281), destination (line 282), after (line 283) are initialized along all control-flow paths (remember to check for exceptions or early returns).
    private Builder() {
            ^
    (see http://t.uber.com/nullaway )

and source

  @Value.Immutable
  @JsonSerialize(as = ImmutableSkeletonConfiguration.class)
  @JsonDeserialize(as = ImmutableSkeletonConfiguration.class)
   interface SkeletonConfiguration {
    SourceType getTemplateSourceType();
    String getSource();
    String getDestination();
    Pattern getAfter();
  }

I’ve tried this and subsets of gradle.build.kts (btw, you might want to update the get started documentation with how do do this)

  annotationProcessor("org.immutables:value:2.+")
  errorprone("org.immutables:value:2.+")
  errorprone("org.immutables:value-annotations:2.+")
  errorprone("com.google.errorprone:error_prone_core:2.4.+")
  errorprone("com.uber.nullaway:nullaway:0.8.+")
  compileOnly("org.immutables:value-annotations:2.+")

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
Stephan202commented, Dec 4, 2020

Are there more comments or advises, especially from the folks who already submitted issues / PRs to fix errorprone/linter stuff?

I’m one of those folks, but have since decided to simply skip Error Prone analysis of generated code. Our Maven build contains the following Error Prone config:

-XepDisableWarningsInGeneratedCode
-XepExcludedPaths:${project.build.directory}${file.separator}.*

(The first flag disables analysis of all @Generated code, even if it’s checked in (🙈). The second flag disables analysis of all code generated at build time, even if not marked @Generated. Additionally, it prevents Error Prone from looking at such code at all, providing a small performance boost.)

For an example see our open-source parent pom.xml. Since we enable nearly all Error Prone checks, skipping analysis of generated code seems to be the only pragmatic approach.

0reactions
xenoterracidecommented, Mar 22, 2021

appears that the @NotNull is probably an issue with the fact that the annotation module isn’t documented, and doesn’t seem to work as advertised.

Read more comments on GitHub >

github_iconTop Results From Across the Web

@Nullable and @NotNull | IntelliJ IDEA Documentation
@Nullable and @NotNull annotations let you check nullability of a variable, parameter, or return value. They help you control contracts ...
Read more >
Update your codebase to use nullable reference types
You turn on nullable reference types as you annotate APIs. When you've finished, you enable nullable reference types for the entire project.
Read more >
Add option to generate C# nullable annotations #6632 - GitHub
C# 8.0 adds support for nullability annotations. It would be helpful if the the generated protobuf objects added these annotations. This would ...
Read more >
The annotation for nullable reference types should only be ...
csproj file. This element configures how the compiler interprets the nullability of types and what warnings are generated.
Read more >
Improve code inspection with annotations - Android Developers
Add @Nullable and @NonNull annotations to check the nullness of a given variable, parameter, or return value. The @Nullable annotation indicates a variable, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found