Skip to content

[build] Configure Google Error Prone static code analysis tool for Pulsar maven build - #8879

Merged
sijie merged 1 commit into
apache:masterfrom
lhotari:lh-error-prone
Dec 10, 2020
Merged

sijie merged 1 commit into
apache:masterfrom
lhotari:lh-error-prone

Conversation

@lhotari

@lhotari lhotari commented Dec 9, 2020 •

Copy link
Copy Markdown
Member

Motivation

Google's Error Prone static code analysis tool 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, lombok.Generated annotation is ignored 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

@lhotari lhotari changed the title Configure Google Error Prone static code analysis tool for Pulsar maven build [build] Configure Google Error Prone static code analysis tool for Pulsar maven build Dec 9, 2020
@sijie sijie added this to the 2.8.0 milestone Dec 9, 2020
@sijie

sijie commented Dec 9, 2020

Copy link
Copy Markdown
Member

/pulsarbot run-failure-checks

@lhotari

lhotari commented Dec 9, 2020

Copy link
Copy Markdown
Member Author

I'll revisit the changes since adding the annotations jar to provided scope will change the dependency resolution. I'll try to find another solution for JDK9+.

- 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
@lhotari

lhotari commented Dec 10, 2020

Copy link
Copy Markdown
Member Author

/pulsarbot run-failure-checks

@sijie
sijie merged commit f540fd3 into apache:master Dec 10, 2020
@asafm

asafm commented Dec 19, 2022

Copy link
Copy Markdown
Contributor

Interesting. I gave it a go after updating to the latest version as the above-mentioned annotation bug was fixed, and it failed compilation without any statement as to why. Weird.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants