Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lombok.Generated annotation is ignored #1863

Closed
sergeykad opened this issue Oct 14, 2020 · 3 comments
Closed

lombok.Generated annotation is ignored #1863

sergeykad opened this issue Oct 14, 2020 · 3 comments

Comments

@sergeykad
Copy link
Contributor

sergeykad commented Oct 14, 2020

Description of the problem / feature request:

Enabling Lombok's @Generated annotation via lombok.addLombokGeneratedAnnotation = true does not reduce the number of reported issues.

Feature requests: what underlying problem are you trying to solve with this feature?

Error Prone ignores the lombok.Generated annotation. Unlike the javax.annotation.processing.Generated annotation this one has @Retention(CLASS) instead of SOURCE.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Adding a few Lombok annotations is usually enough to trigger a violation. There are already some examples available here:
#1700
#1482
#1481

What version of Error Prone are you using?

2.4.0

Have you found anything relevant by searching the web?

No

@tbroyer
Copy link
Contributor

tbroyer commented Oct 16, 2020

It would actually be great if ErrorProne accepted any annotation named Generated whichever the package.

The fact that javax.annotation.processing.Generated has SOURCE retention is a real problem, leading to many code generators to come with their own Generated annotation with CLASS retention (like the now-defunct javax.annotation.Generated): Lombok, Immutables, someone asked it for jOOQ, someone else for MapStruct, and I'm sure there are (many) others.

lhotari added a commit to lhotari/pulsar that referenced this issue Dec 10, 2020
- for more info see https://errorprone.info/

- add a separate maven profile for running errorprone analysis
  it is not active by default

- Add top-level lombok.config file for configuring Lombok.
  This file doesn't contain any other settings that
  marks it as the top most config file with "config.stopBubbling = true"
  (see https://projectlombok.org/features/configuration for reference)

  - Before running the Error Prone analysis, it's necessary to
    manually configure Lombok to add @javax.annotation.Generated("lombok")
    annotation on all fields, methods, and types that are generated.
    This makes Error Prone skip the analysis for Lombok generated code.
    - this setting cannot be enabled by default since JDK9+ doesn't include
      the javax.annotation.Generated annotation by default and adding the
      required dependency will change the classpath dependency resolution results.
    - There is an open issue to support lombok.Generated annotion in
      ErrorProne, google/error-prone#1863

- example usage:
  Configure Lombok to add Generated annotations
  echo "lombok.addJavaxGeneratedAnnotation = true" >> lombok.config
  then,
  on JDK8
  "mvn -Perrorprone,errorprone-jdk8,core-modules compile"
  on JDK11+
  "mvn -Perrorprone,errorprone-jdk11,core-modules compile"

  - usability is better when used together with IntelliJ
    since one can click on the error message to navigate
    to the code location

- also add configuration for Error Prone SLF4J plugin
  https://github.com/KengoTODA/errorprone-slf4j
  which helps detect misusage of SLF4J API
sijie pushed a commit to apache/pulsar that referenced this issue Dec 10, 2020
### Motivation

Google's [Error Prone static code analysis tool](https://errorprone.info/) can detect typical programming mistakes (for more info see https://errorprone.info/). This PR adds configuration to Pulsar maven build so that Error Prone static code analysis
can be run for the Pulsar code base. This additional configuration is not active by default and requires activating `errorprone` and `errorprone-jdk8` or `errorprone-jdk11` maven profiles in addition to `main` or `core-modules` profile for running the analysis.

### Modifications

- add a separate maven profile for running errorprone analysis
  it is not active by default

- Add top-level `lombok.config file` for configuring Lombok.
  This file doesn't contain any other settings that
  marks it as the top most config file with `config.stopBubbling = true`
  (see https://projectlombok.org/features/configuration for reference)

- Before running the Error Prone analysis, it's necessary to
  manually configure Lombok to add `@javax.annotation.Generated("lombok")`
  annotation on all fields, methods, and types that are generated.
  This makes Error Prone skip the analysis for Lombok generated code.
  - this setting cannot be enabled by default since JDK9+ doesn't include
    the `javax.annotation.Generated` annotation by default and adding the
    required dependency will change the classpath dependency resolution results.
  - There is an open issue to support lombok.Generated annotion in
    ErrorProne, google/error-prone#1863

- example usage:
  Configure Lombok to add Generated annotations
  `echo "lombok.addJavaxGeneratedAnnotation = true" >> lombok.config`
  then,
  on JDK8
  `mvn -Perrorprone,errorprone-jdk8,core-modules compile`
  on JDK11+
  `mvn -Perrorprone,errorprone-jdk11,core-modules compile`

  - usability is better when used together with IntelliJ
    since one can click on the error message to navigate
    to the code location

- also add configuration for Error Prone SLF4J plugin
  https://github.com/KengoTODA/errorprone-slf4j
  which helps detect misusage of SLF4J API
@cushon
Copy link
Collaborator

cushon commented Jan 7, 2021

#1984 is a related bug about org.immutables (which I think is supposed to try to use the javax.* annotations if they're available, but doesn't seem to be doing that).

copybara-service bot pushed a commit that referenced this issue Jan 19, 2021
to support non-standard annotations.

Fixes #1984, #1863

PiperOrigin-RevId: 352461144
copybara-service bot pushed a commit that referenced this issue Jan 19, 2021
to support non-standard annotations.

Fixes #1984, #1863

PiperOrigin-RevId: 352622403
@cushon
Copy link
Collaborator

cushon commented Jan 20, 2021

It would actually be great if ErrorProne accepted any annotation named Generated whichever the package.

Done: 4d6a0cc

That doesn't solve all of our problems with lombok (see #1250 (comment) for current thoughts on that), but it should be enough to recognize lombok's annotation in -XepDisableWarningsInGeneratedCode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants