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

Error Prone is not recoginizing the symbols and imports #3681

Closed
jchen293 opened this issue Jan 3, 2023 · 7 comments
Closed

Error Prone is not recoginizing the symbols and imports #3681

jchen293 opened this issue Jan 3, 2023 · 7 comments

Comments

@jchen293
Copy link

jchen293 commented Jan 3, 2023

Hi all. I am trying to add error prone to the EasyPost Java repo. Currently, I am using the below shell script to run the error prone check, however, the error prone would throw hundreds of errors saying cannot find the path and cannot recognize the import. Has anyone encountered this in the past? Any advice would be much appreciated!

# This script must be used with Java 9+

# Error Prone newer than 2.10.0 doesn't work on Java 8-10
EP_VERSION="2.10.0"

# Install needed jars
wget -nc -q https://repo1.maven.org/maven2/com/google/errorprone/error_prone_core/${EP_VERSION?}/error_prone_core-${EP_VERSION?}-with-dependencies.jar
wget -nc -q https://repo1.maven.org/maven2/org/checkerframework/dataflow-errorprone/3.15.0/dataflow-errorprone-3.15.0.jar
wget -nc -q https://repo1.maven.org/maven2/com/google/code/findbugs/jFormatString/3.0.0/jFormatString-3.0.0.jar

# Run Error Prone on the library and test suite
javac \
  -J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
  -J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
  -J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED \
  -J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED \
  -J--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
  -J--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED \
  -J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
  -J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED \
  -J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED \
  -J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED \
  -XDcompilePolicy=simple \
  -processorpath error_prone_core-${EP_VERSION?}-with-dependencies.jar:dataflow-errorprone-3.15.0.jar:jFormatString-3.0.0.jar \
  '-Xplugin:ErrorProne' \
  src/main/java/com/easypost/**/*.java

Screen Shot 2023-01-03 at 6 54 06 PM

@jchen293 jchen293 changed the title Error Prone is not recoginizing the symbol, import, and Error Prone is not recoginizing the symbols and imports Jan 3, 2023
@Stephan202
Copy link
Contributor

I see that Easypost is a Maven project; the approach taken here will be hard to get working. Instead follow the Maven installation instructions. (I don't know whether these instructions are accurate for the old 2.10 release; it might pay off to find an old gh-pages revision from around the time of that release.)

@jchen293
Copy link
Author

jchen293 commented Jan 4, 2023

I see that Easypost is a Maven project; the approach taken here will be hard to get working. Instead follow the Maven installation instructions. (I don't know whether these instructions are accurate for the old 2.10 release; it might pay off to find an old gh-pages revision from around the time of that release.)

Thanks for replying. Because our Java client library supports Java 8 - 19, I was following the given instruction from the error prone GitHub installation guide for Java 9 or newer so we can run the shell script only once in the CI build for Java 9. I have followed almost everything from the installation requirement, I am unsure if I miss any tiny piece on my end or if there is an issue with error prone 2.10.0 version.

@tbroyer
Copy link
Contributor

tbroyer commented Jan 4, 2023

At a minimum, your classpath is empty, but your POM has many dependencies declared, so it's almost guaranteed to not compile. Your processorpath is also missing Lombok that your project is using.

I'd rather configure ErrorProne in the POM, and use a Maven profile to actually configure it only for Java 9+
But first you have to fully understand your build's requirements and ErrorProne requirements, and how to use/configure Maven profiles (and Maven's combine.children which would be helpful here to add to the compiler arguments and annotation processor path).

Wrt the --add-opens et al. instead of using .mvn/jvm.config (which would apply to Java 8 as well and break the build), you can configure the maven-compiler-plugin with <fork>true</fork> and pass them as compiler arguments as -J--add-opens. Note that the fork=true will slightly slow your build.

@Stephan202
Copy link
Contributor

I started writing a comment (and then got distracted), but @tbroyer already gave an excellent answer. Flushing the text I had so far:

@jchen293 to get this script to work you'll have to modify it so that (a) the relevant dependencies are added to the classpath and (b) javac doesn't think that src.main.java is a package prefix. This can be done of course (it's what the maven-compiler-plugin does under the hood), but even if you succeed, you'd have to keep the script in sync with with the pom.xml configuration.

@jchen293
Copy link
Author

jchen293 commented Jan 4, 2023

@tbroyer @Stephan202 Thank you all for the inputs! I have removed the shell script and edited the configuration in POM as you guys suggested. I am using version 2.10.0 and having one last issue, the build would only fail on Java 8. I have added the <fork>true</fork> as Thomas suggests. At this point, I am kind of running out of ideas on what I need to add or anything that I miss to avoid the build failure on Java 8. I really appreciate it if you guys could give me some hints on the last issue I am facing.

Build with Java 8: https://github.com/EasyPost/easypost-java/actions/runs/3840568957/jobs/6539781354
Build without Java 8: https://github.com/EasyPost/easypost-java/actions/runs/3840589366

@tbroyer
Copy link
Contributor

tbroyer commented Jan 4, 2023

I believe the -J--add-exports/-J--add-opens should only be added when running with Java 9+, but Java 8 (still supported with ErrorProne 2.10) needs some special treatment as well.

See https://errorprone.info/docs/installation#jdk-8, and more specifically https://github.com/google/error-prone/blob/f8e33bc460be82ab22256a7ef8b979d7a2cacaba/docs/installation.md#maven
(I would put the -J-add-exports and -J--add-opens in a Java 9+ Maven profile for good measure)

Another approach is to always build with the same JDK (e.g. JDK 11 or JDK 17, with <release>8</release> to ensure compatibility with Java 8) and use Maven toolchains to run tests with various Java versions.

@jchen293
Copy link
Author

jchen293 commented Jan 6, 2023

Closing this issue, we have decided to modify our CI build to use JDK 19 to build Java 8 - 19. Thanks all for the help!

@jchen293 jchen293 closed this as completed Jan 6, 2023
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