VladRassokhin/intellij-annotations-instrumenter-maven-plugin

ClassNotFoundException

Closed this issue · 5 comments

I'm getting this when attempting to run a mvn install:

[ERROR] Failed to execute goal com.intellij:notnull-instrumenter-maven-plugin:1.0-SNAPSHOT:instrument (default) on project Logging: @NotNull instrumentation failed for C:\projects\PluginBase\logging\target\classes\com\dumptruckman\minecraft\pluginbase\logging\DebugLog.class: java.lang.RuntimeException: java.lang.ClassNotFoundException: Class not found: java/lang/SecurityException -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.intellij:notnull-instrumenter-maven-plugin:1.0-SNAPSHOT:instrument (default) on project Logging: @NotNull instrumentation failed for C:\projects\PluginBase\logging\target\classes\com\dumptruckman\minecraft\pluginbase\logging\DebugLog.class: java.lang.RuntimeException: java.lang.ClassNotFoundException: Class not found: java/lang/SecurityException
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
    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:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
    at org.codehaus.classworlds.Launcher.main(Launcher.java:47)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: org.apache.maven.plugin.MojoExecutionException: @NotNull instrumentation failed for C:\projects\PluginBase\logging\target\classes\com\dumptruckman\minecraft\pluginbase\logging\DebugLog.class: java.lang.RuntimeException: java.lang.ClassNotFoundException: Class not found: java/lang/SecurityException
    at com.intellij.AbstractNotNullInstrumenterTask.instrumentDirectoryRecursive(AbstractNotNullInstrumenterTask.java:69)
    at com.intellij.AbstractNotNullInstrumenterTask.instrument(AbstractNotNullInstrumenterTask.java:55)
    at com.intellij.ClassesNotNullInstrumenter.execute(ClassesNotNullInstrumenter.java:38)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    ... 25 more
Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: Class not found: java/lang/SecurityException
    at com.intellij.compiler.instrumentation.InstrumenterClassWriter.getCommonSuperClass(InstrumenterClassWriter.java:56)
    at org.objectweb.asm.ClassWriter.a(Unknown Source)
    at org.objectweb.asm.Frame.a(Unknown Source)
    at org.objectweb.asm.Frame.a(Unknown Source)
    at org.objectweb.asm.MethodWriter.visitMaxs(Unknown Source)
    at org.objectweb.asm.MethodVisitor.visitMaxs(Unknown Source)
    at com.intellij.compiler.notNullVerification.NotNullVerifyingInstrumenter$1.visitMaxs(NotNullVerifyingInstrumenter.java:150)
    at org.objectweb.asm.ClassReader.accept(Unknown Source)
    at org.objectweb.asm.ClassReader.accept(Unknown Source)
    at com.intellij.AbstractNotNullInstrumenterTask.instrumentClass(AbstractNotNullInstrumenterTask.java:86)
    at com.intellij.AbstractNotNullInstrumenterTask.instrumentDirectoryRecursive(AbstractNotNullInstrumenterTask.java:65)
    ... 29 more
Caused by: java.lang.ClassNotFoundException: Class not found: java/lang/SecurityException
    at com.intellij.compiler.instrumentation.InstrumentationClassFinder.loadClass(InstrumentationClassFinder.java:144)
    at com.intellij.compiler.instrumentation.InstrumenterClassWriter.getCommonSuperClass(InstrumenterClassWriter.java:35)
    ... 39 more

I found a similar problem on a class I didn't actually use and found that removing the class solved the issue.

The class the error is referring to can be found here: https://github.com/dumptruckman/PluginBase/blob/master/logging/src/main/java/com/dumptruckman/minecraft/pluginbase/logging/DebugLog.java

This would be with the 1.0-SNAPSHOT on the repository listed in the README.

I got the same problem in one of our projects (several other projects work which is strange). So I started messing around a bit with the plugin source. And after a while I added the following to the end of ClassFinderClasspath constructor (InstrumentationClassFinder.java line 206), I got it to work.

        for (URL url : myUrls) { // just to see what is already there
            System.out.println("url = " + url);
        }
        try { // add missing rt.jar to classpath
            myUrls.push(new File("C:/jdk/java/jdk1.7.0_05/jre/lib/rt.jar").toURI().toURL());
        } catch (MalformedURLException ignore) {
        }

Note that this is not a good solution (as it is hardcoded to my Java location). I don't even know if adding rt.jar to Loader URLs is a bad thing or not?

If rt.jar should be added to loader path is there good way to locate it from a Maven plugin?

/Olle

diff --git a/src/main/java/com/intellij/AbstractNotNullInstrumenterTask.java b/src/main/java/com/intellij/AbstractNotNullInstrumenterTask.java
index 17fa1e3..a39a690 100644
--- a/src/main/java/com/intellij/AbstractNotNullInstrumenterTask.java
+++ b/src/main/java/com/intellij/AbstractNotNullInstrumenterTask.java
@@ -48,6 +48,8 @@ public abstract class AbstractNotNullInstrumenterTask extends org.apache.maven.p
for (String cp : classpathElements) {
urls.add(new File(cp).toURI().toURL());
}

  •        urls.add(new File(System.getProperty("java.class.path")).toURI().toURL());
    
  •        urls.add(new File(System.getProperty("java.home")+"/lib/rt.jar").toURI().toURL());
     } catch (MalformedURLException e) {
         throw new MojoExecutionException("Cannot convert classpath element into URL", e);
     }
    

Correct the problem

Managed an even simpler solution that seems to work:

Index: src/main/java/com/intellij/compiler/instrumentation/InstrumentationClassFinder.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/main/java/com/intellij/compiler/instrumentation/InstrumentationClassFinder.java (date 1373285082000)
+++ src/main/java/com/intellij/compiler/instrumentation/InstrumentationClassFinder.java (revision )
@@ -54,7 +54,7 @@
     // look into classpath
     final Resource resource = myClasspath.getResource(resourceName, false);
     if (resource == null) {
-      throw new ClassNotFoundException("Class not found: " + internalName);
+      is = ClassLoader.getSystemResourceAsStream(resourceName);
     } else {
       is = resource.getInputStream();
     }

This might still not be totally correct if you have specified a compiler in the maven-compiler-plugin, since the notnull-instrumenter-maven-plugin would run the Maven (JAVA_HOME) compiler. But it is good enough for me :-)

Fixed. New snapshot deployed