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

UnusedNestedClass leads to NullPointerException (with repro) #1240

Closed
zimmi opened this issue Mar 6, 2019 · 2 comments · Fixed by #1369
Closed

UnusedNestedClass leads to NullPointerException (with repro) #1240

zimmi opened this issue Mar 6, 2019 · 2 comments · Fixed by #1369
Assignees

Comments

@zimmi
Copy link

zimmi commented Mar 6, 2019

Description of the problem / feature request:

I'm trying to export a package containing a nested static inner class through module-info.java. This seems to trigger the UnusedNestedClass rule (which it shouldn't, as the inner class is public and therefore exported, but this is probably a separate problem). This leads to the following stacktrace:

module-info.java:[1,1] An unhandled exception was thrown by the Error Prone static analysis plugin.
     Please report this at https://github.com/google/error-prone/issues/new and include the following:
  
     error-prone version: 2.3.3
     BugPattern: UnusedNestedClass
     Stack Trace:
     java.lang.NullPointerException
  	at com.google.errorprone.util.ASTHelpers.enclosingClass(ASTHelpers.java:880)
  	at com.google.errorprone.bugpatterns.UnusedNestedClass$ClassUsageScanner.handle(UnusedNestedClass.java:116)
  	at com.google.errorprone.bugpatterns.UnusedNestedClass$ClassUsageScanner.visitMemberSelect(UnusedNestedClass.java:105)
  	at com.google.errorprone.bugpatterns.UnusedNestedClass$ClassUsageScanner.visitMemberSelect(UnusedNestedClass.java:87)
  	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:2118)
  	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
  	at jdk.compiler/com.sun.source.util.TreeScanner.visitRequires(TreeScanner.java:880)
  	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCRequires.accept(JCTree.java:2852)
  	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
  	at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:105)
  	at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:113)
  	at jdk.compiler/com.sun.source.util.TreeScanner.visitModule(TreeScanner.java:853)
  	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCModuleDecl.accept(JCTree.java:2701)
  	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
  	at jdk.compiler/com.sun.source.util.TreeScanner.scan(TreeScanner.java:105)
  	at jdk.compiler/com.sun.source.util.TreeScanner.scanAndReduce(TreeScanner.java:113)
  	at jdk.compiler/com.sun.source.util.TreeScanner.visitCompilationUnit(TreeScanner.java:144)
  	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:591)
  	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:56)
  	at com.google.errorprone.bugpatterns.UnusedNestedClass.matchCompilationUnit(UnusedNestedClass.java:62)
  	at com.google.errorprone.scanner.ErrorProneScanner.processMatchers(ErrorProneScanner.java:433)
  	at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:541)
  	at com.google.errorprone.scanner.ErrorProneScanner.visitCompilationUnit(ErrorProneScanner.java:150)
  	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:591)
  	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:56)
  	at com.google.errorprone.scanner.Scanner.scan(Scanner.java:55)
  	at com.google.errorprone.scanner.ErrorProneScannerTransformer.apply(ErrorProneScannerTransformer.java:43)
  	at com.google.errorprone.ErrorProneAnalyzer.finished(ErrorProneAnalyzer.java:147)
  	at jdk.compiler/com.sun.tools.javac.api.MultiTaskListener.finished(MultiTaskListener.java:132)
  	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1418)
  	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.flow(JavaCompiler.java:1365)
  	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:960)
  	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:104)
  	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.handleExceptions(JavacTaskImpl.java:147)
  	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:100)
  	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:94)
  	at org.codehaus.plexus.compiler.javac.JavaxToolsCompiler.compileInProcess(JavaxToolsCompiler.java:126)
  	at org.codehaus.plexus.compiler.javac.JavacCompiler.performCompile(JavacCompiler.java:174)
  	at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:1129)
  	at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:188)
  	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
  	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
  	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
  	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
  	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
  	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
  	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
  	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
  	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
  	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
  	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
  	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
  	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
  	at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
  	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
  	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
  	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
  	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
  	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

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

  1. Clone https://github.com/zimmi/unused-nested-repro
  2. Run mvn clean package to see the error message
  3. Adding exports org.example; to module-info.java does not make a difference to trigger the error.
  4. Removing the line requires java.base; from module-info.java makes it work somehow (adding any other requires clause seems to also make it fail).

What version of Error Prone are you using?

2.3.3

java --version:

openjdk 11.0.2 2019-01-15
OpenJDK Runtime Environment (build 11.0.2+9-Debian-3)
OpenJDK 64-Bit Server VM (build 11.0.2+9-Debian-3, mixed mode, sharing)

Have you found anything relevant by searching the web?

No.

@tapacuk93
Copy link

Catched same problem.

@cpovirk
Copy link
Member

cpovirk commented Oct 4, 2019

I think I have a fix.

@nick-someone nick-someone mentioned this issue Oct 9, 2019
nick-someone pushed a commit that referenced this issue Oct 9, 2019
This solves a problem with UnusedNestedClass on module-info.java files.

Fixes #1240
Somewhat relevant to google/guava-beta-checker#8

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=273590160
nick-someone pushed a commit that referenced this issue Oct 9, 2019
This solves a problem with UnusedNestedClass on module-info.java files.

Fixes #1240
Somewhat relevant to google/guava-beta-checker#8

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=273590160
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

Successfully merging a pull request may close this issue.

3 participants