Custom BugChecker test error: java.lang.NoSuchFieldError: ANNOTATION_PROCESSOR_MODULE_PATH

412 views
Skip to first unread message

rafaelps...@gmail.com

unread,
Feb 7, 2018, 1:08:31 PM2/7/18
to error-prone-discuss
Hi everybody,

I'm writing some example code to learn Error Prone features. Currently I'm following https://github.com/google/error-prone/wiki/Writing-a-check to write my custom checks. Unfortunately I'm not able to unit test these checks because my test setup is raising a java.lang.NoSuchFieldError: ANNOTATION_PROCESSOR_MODULE_PATH. I debugged and found that this exception comes from StandardLocation.java that is present on rt.jar (1.8) and com.google.errorprone:javac:9+181-r4173-1 (and the classpath probably should load it from javac:9+181-r4173-1)

Any ideas on that?

JVM: 1.8.0_161 (Oracle Corporation 25.161-b12)
Error Prone: 2.2.0
Gradle: 4.5
Code: https://github.com/rafaelpsouza/errorprone-spikes/tree/master/custom-checkers

Stack trace:

java.lang.NoSuchFieldError: ANNOTATION_PROCESSOR_MODULE_PATH

    at com
.sun.tools.javac.file.Locations.initHandlers(Locations.java:1976)
    at com
.sun.tools.javac.file.Locations.<init>(Locations.java:145)
    at com
.sun.tools.javac.file.BaseFileManager.createLocations(BaseFileManager.java:115)
    at com
.sun.tools.javac.file.BaseFileManager.<init>(BaseFileManager.java:76)
    at com
.sun.tools.javac.file.JavacFileManager.<init>(JavacFileManager.java:147)
    at com
.google.errorprone.ErrorProneInMemoryFileManager.<init>(ErrorProneInMemoryFileManager.java:66)
    at com
.google.errorprone.ErrorProneInMemoryFileManager.<init>(ErrorProneInMemoryFileManager.java:62)
    at com
.google.errorprone.CompilationTestHelper.<init>(CompilationTestHelper.java:76)
    at com
.google.errorprone.CompilationTestHelper.newInstance(CompilationTestHelper.java:115)
    at br
.eng.rafaelpsouza.errorprone.DoNotReturnNullTest.setup(DoNotReturnNullTest.java:19)
    at sun
.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun
.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun
.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java
.lang.reflect.Method.invoke(Method.java:498)
    at org
.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org
.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org
.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org
.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
    at org
.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org
.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org
.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org
.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org
.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org
.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org
.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org
.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org
.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org
.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com
.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com
.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com
.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com
.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)


Rafael de Paula Souza

unread,
Feb 8, 2018, 1:55:06 PM2/8/18
to error-prone-discuss

Eddie Aftandilian

unread,
Feb 8, 2018, 2:05:57 PM2/8/18
to error-prone-discuss
This looks like you are not setting the bootclasspath properly for the test execution.  You need to add -Xbootclasspath/p:<path_to_error_prone_javac.jar> to the JVM invocation that runs your test.  I'm not sure how you are executing this test, but you can see how we do it in Maven here: 

Rafael de Paula Souza

unread,
Feb 16, 2018, 12:11:42 PM2/16/18
to error-prone-discuss
Yes, I was not setting bootclasspath properly for the test execution. I added -Xbootclasspath and now it's working.

If someone is interested here is an example of custom checks and gradle: https://github.com/rafaelpsouza/static-code-analysis-spikes/tree/master/errorprone

Thanks Eddie,
Reply all
Reply to author
Forward
0 new messages