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.

Consider providing a com.sun.source.util.Plugin?

See original GitHub issue

I recently became aware of ErrorProne as @davido is working to integrate it into Buck. Glancing at the code, it looks like the key reason for exposing it as a compiler is to get a TaskListener into place, which is exactly what the Plugin facility lets you do in javac 8 and higher. Plugins can be auto-discovered on the processor path (just like annotation processors), which would make it more straightforward to run ErrorProne even with command-line javac, and of course any build system that supports Plugins (I’m working to add such support to Buck) would no longer require a special integration.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
ttsugriycommented, Feb 22, 2018

@cushon, I’m getting a following stack trace when using modern ant compiler with -processorpath pointing at error_prone_ant-2.2.0.jar and -Xplugin:ErrorProne:

    [javac] A plugin threw an uncaught exception.
    [javac] Consult the following stack trace for details.
    [javac] java.lang.NoSuchMethodError: com.sun.tools.javac.util.JavacMessages.add(Lcom/sun/tools/javac/util/JavacMessages$ResourceBundleHelper;)V
    [javac] 	at com.google.errorprone.BaseErrorProneJavaCompiler.setupMessageBundle(BaseErrorProneJavaCompiler.java:189)
    [javac] 	at com.google.errorprone.ErrorProneJavacPlugin.init(ErrorProneJavacPlugin.java:38)
    [javac] 	at com.sun.tools.javac.main.Main.compile(Main.java:470)
    [javac] 	at com.sun.tools.javac.main.Main.compile(Main.java:381)
    [javac] 	at com.sun.tools.javac.main.Main.compile(Main.java:370)
    [javac] 	at com.sun.tools.javac.main.Main.compile(Main.java:361)
    [javac] 	at com.sun.tools.javac.Main.compile(Main.java:56)
    [javac] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [javac] 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    [javac] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    [javac] 	at java.lang.reflect.Method.invoke(Method.java:498)
    [javac] 	at org.apache.tools.ant.taskdefs.compilers.Javac13.execute(Javac13.java:57)
    [javac] 	at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:1407)
    [javac] 	at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:1133)
    [javac] 	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
    [javac] 	at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    [javac] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    [javac] 	at java.lang.reflect.Method.invoke(Method.java:498)
    [javac] 	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    [javac] 	at org.apache.tools.ant.Task.perform(Task.java:346)
    [javac] 	at java.util.Vector.forEach(Vector.java:1249)
    [javac] 	at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:67)
    [javac] 	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
    [javac] 	at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    [javac] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    [javac] 	at java.lang.reflect.Method.invoke(Method.java:498)
    [javac] 	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    [javac] 	at org.apache.tools.ant.Task.perform(Task.java:346)
    [javac] 	at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:394)
    [javac] 	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
    [javac] 	at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    [javac] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    [javac] 	at java.lang.reflect.Method.invoke(Method.java:498)
    [javac] 	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    [javac] 	at org.apache.tools.ant.Task.perform(Task.java:346)
    [javac] 	at org.apache.tools.ant.Target.execute(Target.java:448)
    [javac] 	at org.apache.tools.ant.Target.performTasks(Target.java:469)
    [javac] 	at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
    [javac] 	at org.apache.tools.ant.Project.executeTarget(Project.java:1370)
    [javac] 	at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    [javac] 	at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
    [javac] 	at org.apache.tools.ant.Main.runBuild(Main.java:849)
    [javac] 	at org.apache.tools.ant.Main.startAnt(Main.java:228)
    [javac] 	at org.apache.tools.ant.launch.Launcher.run(Launcher.java:283)
    [javac] 	at org.apache.tools.ant.launch.Launcher.main(Launcher.java:101)

I’m I doing something obviously wrong? Is -J-Xbootclasspath/p:javac-9-dev-r3297-4.jar required for using ErrorProne plugin? I’m using java version "1.8.0_144"

1reaction
cushoncommented, Aug 10, 2018

I can reproduce:

$ javac -version
javac 1.8.0_162
$ javac -XDcompilePolicy=simple -processorpath error_prone_ant-2.3.1.jar \
  '-Xplugin:ErrorProne -XepDisableAllChecks -Xep:CollectionIncompatibleType:ERROR' \
  ShortSet.java
A plugin threw an uncaught exception.
Consult the following stack trace for details.
java.lang.NoSuchMethodError: com.sun.tools.javac.util.JavacMessages.add(Lcom/sun/tools/javac/util/JavacMessages$ResourceBundleHelper;)V
	at com.google.errorprone.BaseErrorProneJavaCompiler.setupMessageBundle(BaseErrorProneJavaCompiler.java:203)
	at com.google.errorprone.ErrorProneJavacPlugin.init(ErrorProneJavacPlugin.java:40)
	at com.sun.tools.javac.main.Main.compile(Main.java:470)
	at com.sun.tools.javac.main.Main.compile(Main.java:381)
	at com.sun.tools.javac.main.Main.compile(Main.java:370)
	at com.sun.tools.javac.main.Main.compile(Main.java:361)
	at com.sun.tools.javac.Main.compile(Main.java:56)
	at com.sun.tools.javac.Main.main(Main.java:42)

The -Xplugin integration doesn’t work with JDK 8.

It does work with JDK 9:

$ javac -fullversion
javac full version "9+181"
$ javac -XDcompilePolicy=simple -processorpath error_prone_ant-2.3.1.jar \
  '-Xplugin:ErrorProne -XepDisableAllChecks -Xep:CollectionIncompatibleType:ERROR' \
  ShortSet.java
ShortSet.java:7: error: [CollectionIncompatibleType] Argument 'i - 1' should not be passed to this method; its type int is not compatible with its collection's type argument Short
      s.remove(i - 1);
              ^
    (see http://errorprone.info/bugpattern/CollectionIncompatibleType)
1 error

And it also works if you override JDK 8’s javac with the Error Prone javac:

$ javac -J-Xbootclasspath/p:javac-9+181-r4173-1.jar -XDcompilePolicy=simple \
  -processorpath error_prone_ant-2.3.1.jar \
  '-Xplugin:ErrorProne -XepDisableAllChecks -Xep:CollectionIncompatibleType:ERROR' \
  ShortSet.java
ShortSet.java:7: error: [CollectionIncompatibleType] Argument 'i - 1' should not be passed to this method; its type int is not compatible with its collection's type argument Short
      s.remove(i - 1);
              ^
    (see http://errorprone.info/bugpattern/CollectionIncompatibleType)
1 error

@tbroyer is there a way to make gradle do the equivalent of overriding the host JDK’s javac using -J-Xbootclasspath/p:javac-9+181-r4173-1.jar?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Plugin (Compiler Tree API ) - Oracle Help Center
The javac plug-in mechanism allows a user to specify one or more plug-ins on the javac command line, to be started soon after...
Read more >
java - Javac - plugin not found - Stack Overflow
"To achieve this, we need to create a file named com.sun.source.util.Plugin with content which is our plugin's fully qualified class name ...
Read more >
The Java Plugin - Gradle User Manual
The Java plugin adds a number of tasks to your project, as shown below. ... Compiles production Java source files using the JDK...
Read more >
Processing Code - OpenJDK
The Annotation Processing API, providing a way to execute code within javac that could analyze the classes ... DocTreeScanner; import com.sun.source.util.
Read more >
Transition from Java 8 to Java 11 - Azure - Microsoft Learn
There are jdeps and jdeprscan plugins for both Gradle and Maven. ... Util class is calling a deprecated constructor of the java.lang.
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