Class loader fails to load nested Java class from a JAR
In an attached archive there are two equivalent projects - in Java and Scala.
The problem is Java interface FullUser32 referencing a JAR file. It works in Java, but in Scala project it fails in runtime until you uncomment one additional import in its file. If you add this import, compiler warns: "The import com.sun.jna.platform.win32.WinDef.HWND is never used FullUser32.java /a/src/b line 6", but scala program starts working.
In both cases, no compilation problems are reported. No errors are logged in Eclipse Error log. The only hint is scala-ide.log reporting class loading fail (reported only once per session?).
The project has to be cleaned each time a proper Main class is compiled as it will execute fine even if its code is changed later. This might indicate some problems with incremental compilation. Eclipse restarts might also affect reproducibility (not sure).
scala-ide.log:
Scala plugin version: 4.0.0.nightly-2_11-201312140620-1d0a313
Scala compiler version: 2.11.0.v20131212-075740-73cddba169
Scala library version: 2.11.0.v20131212-075740-73cddba169
Eclipse version: 4.2.2.v201302041200
The problem is Java interface FullUser32 referencing a JAR file. It works in Java, but in Scala project it fails in runtime until you uncomment one additional import in its file. If you add this import, compiler warns: "The import com.sun.jna.platform.win32.WinDef.HWND is never used FullUser32.java /a/src/b line 6", but scala program starts working.
In both cases, no compilation problems are reported. No errors are logged in Eclipse Error log. The only hint is scala-ide.log reporting class loading fail (reported only once per session?).
The project has to be cleaned each time a proper Main class is compiled as it will execute fine even if its code is changed later. This might indicate some problems with incremental compilation. Eclipse restarts might also affect reproducibility (not sure).
scala-ide.log:
2013-12-14 22:29:52,889 ERROR [main] - org.scala-ide.sdt.core - org.scala-ide.sdt.core - org.scala-ide.sdt.core - 0 - Error during askOption
java.lang.InterruptedException
at java.lang.Object.wait(Native Method)
at scala.tools.nsc.interactive.Response.get(Response.scala:77)
at scala.tools.eclipse.ScalaPresentationCompiler.askOption(ScalaPresentationCompiler.scala:216)
at scala.tools.eclipse.ScalaPresentationCompiler.askOption(ScalaPresentationCompiler.scala:207)
at scala.tools.eclipse.ScalaHover$$anonfun$getHoverInfo$1.scala$tools$eclipse$ScalaHover$$anonfun$$hoverInfo$1(ScalaHover.scala:25)
at scala.tools.eclipse.ScalaHover$$anonfun$getHoverInfo$1$$anonfun$apply$3.apply(ScalaHover.scala:42)
at scala.tools.eclipse.ScalaHover$$anonfun$getHoverInfo$1$$anonfun$apply$3.apply(ScalaHover.scala:41)
at scala.Option.flatMap(Option.scala:170)
at scala.tools.eclipse.ScalaHover$$anonfun$getHoverInfo$1.apply(ScalaHover.scala:41)
at scala.tools.eclipse.ScalaHover$$anonfun$getHoverInfo$1.apply(ScalaHover.scala:22)
at scala.tools.eclipse.InteractiveCompilationUnit$$anonfun$withSourceFile$1.apply(InteractiveCompilationUnit.scala:68)
at scala.tools.eclipse.InteractiveCompilationUnit$$anonfun$withSourceFile$1.apply(InteractiveCompilationUnit.scala:68)
at scala.tools.eclipse.ScalaPresentationCompilerProxy$$anonfun$apply$1.apply(ScalaPresentationCompilerProxy.scala:72)
at scala.tools.eclipse.ScalaPresentationCompilerProxy$$anonfun$apply$1.apply(ScalaPresentationCompilerProxy.scala:72)
at scala.Option.flatMap(Option.scala:170)
at scala.tools.eclipse.ScalaPresentationCompilerProxy.apply(ScalaPresentationCompilerProxy.scala:72)
at scala.tools.eclipse.InteractiveCompilationUnit$class.withSourceFile(InteractiveCompilationUnit.scala:68)
at scala.tools.eclipse.javaelements.ScalaSourceFile.withSourceFile(ScalaSourceFile.scala:77)
at scala.tools.eclipse.ScalaHover.getHoverInfo(ScalaHover.scala:22)
at org.eclipse.jface.text.TextViewerHoverManager$4.run(TextViewerHoverManager.java:168)
2013-12-15 13:36:07,430 ERROR [main] - org.scala-ide.sdt.core - org.scala-ide.sdt.core - org.scala-ide.sdt.core - 0 - Java Model Exception: Java Model Status [MAIN$ [in [Working copy] MAIN.scala [in minefinder.grid [in src [in minefinder]]]] does not exist]
2013-12-15 13:41:14,877 ERROR [main] - org.scala-ide.sdt.core - org.scala-ide.sdt.core - org.scala-ide.sdt.core - 0 - Java Model Exception: Java Model Status [Main$ [in [Working copy] Main.scala [in <default> [in src [in a]]]] does not exist]
2013-12-15 13:43:35,119 ERROR [main] - org.scala-ide.sdt.core - org.scala-ide.sdt.core - org.scala-ide.sdt.core - 0 - Error in Scala compiler
java.lang.NoClassDefFoundError: HWND
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2442)
at java.lang.Class.getDeclaredMethods(Class.java:1808)
at sbt.ClassToAPI$.structure(ClassToAPI.scala:73)
at sbt.ClassToAPI$.x$2$lzycompute$1(ClassToAPI.scala:62)
at sbt.ClassToAPI$.x$2$1(ClassToAPI.scala:62)
at sbt.ClassToAPI$.instance$lzycompute$1(ClassToAPI.scala:62)
at sbt.ClassToAPI$.sbt$ClassToAPI$$instance$1(ClassToAPI.scala:62)
at sbt.ClassToAPI$$anonfun$5.apply(ClassToAPI.scala:63)
at sbt.ClassToAPI$$anonfun$5.apply(ClassToAPI.scala:63)
at xsbti.SafeLazy$Impl._t$lzycompute(SafeLazy.scala:20)
at xsbti.SafeLazy$Impl._t(SafeLazy.scala:18)
at xsbti.SafeLazy$Impl.get(SafeLazy.scala:24)
at sbt.ClassToAPI$$anonfun$process$1.apply(ClassToAPI.scala:22)
at sbt.ClassToAPI$$anonfun$process$1.apply(ClassToAPI.scala:22)
at scala.collection.immutable.List.foreach(List.scala:302)
at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
at scala.collection.mutable.ListBuffer.foreach(ListBuffer.scala:44)
at sbt.ClassToAPI$.process(ClassToAPI.scala:22)
at sbt.compiler.AggressiveCompile$$anonfun$3.sbt$compiler$AggressiveCompile$$anonfun$$readAPI$1(AggressiveCompile.scala:130)
at sbt.compiler.AggressiveCompile$$anonfun$3$$anonfun$compileJava$1$2$$anonfun$apply$mcV$sp$2$$anonfun$apply$6.apply(AggressiveCompile.scala:138)
at sbt.compiler.AggressiveCompile$$anonfun$3$$anonfun$compileJava$1$2$$anonfun$apply$mcV$sp$2$$anonfun$apply$6.apply(AggressiveCompile.scala:138)
at sbt.classfile.Analyze$$anonfun$apply$9.apply(Analyze.scala:45)
at sbt.classfile.Analyze$$anonfun$apply$9.apply(Analyze.scala:43)
at scala.collection.TraversableLike$WithFilter$$anonfun$foreach$1.apply(TraversableLike.scala:778)
at scala.collection.mutable.HashMap$$anonfun$foreach$1.apply(HashMap.scala:99)
at scala.collection.mutable.HashMap$$anonfun$foreach$1.apply(HashMap.scala:99)
at scala.collection.mutable.HashTable$class.foreachEntry(HashTable.scala:230)
at scala.collection.mutable.HashMap.foreachEntry(HashMap.scala:40)
at scala.collection.mutable.HashMap.foreach(HashMap.scala:99)
at scala.collection.TraversableLike$WithFilter.foreach(TraversableLike.scala:777)
at sbt.classfile.Analyze$.apply(Analyze.scala:43)
at sbt.compiler.AggressiveCompile$$anonfun$3$$anonfun$compileJava$1$2$$anonfun$apply$mcV$sp$2.apply(AggressiveCompile.scala:138)
at sbt.compiler.AggressiveCompile$$anonfun$3$$anonfun$compileJava$1$2$$anonfun$apply$mcV$sp$2.apply(AggressiveCompile.scala:136)
at scala.collection.TraversableLike$WithFilter$$anonfun$foreach$1.apply(TraversableLike.scala:778)
at scala.collection.immutable.List.foreach(List.scala:302)
at scala.collection.TraversableLike$WithFilter.foreach(TraversableLike.scala:777)
at sbt.compiler.AggressiveCompile$$anonfun$3$$anonfun$compileJava$1$2.apply$mcV$sp(AggressiveCompile.scala:136)
at sbt.compiler.AggressiveCompile$$anonfun$3$$anonfun$compileJava$1$2.apply(AggressiveCompile.scala:136)
at sbt.compiler.AggressiveCompile$$anonfun$3$$anonfun$compileJava$1$2.apply(AggressiveCompile.scala:136)
at sbt.compiler.AggressiveCompile.sbt$compiler$AggressiveCompile$$timed(AggressiveCompile.scala:159)
at sbt.compiler.AggressiveCompile$$anonfun$3.compileJava$1(AggressiveCompile.scala:135)
at sbt.compiler.AggressiveCompile$$anonfun$3.apply(AggressiveCompile.scala:142)
at sbt.compiler.AggressiveCompile$$anonfun$3.apply(AggressiveCompile.scala:86)
at sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:38)
at sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:36)
at sbt.inc.Incremental$.cycle(Incremental.scala:73)
at sbt.inc.Incremental$$anonfun$1.apply(Incremental.scala:33)
at sbt.inc.Incremental$$anonfun$1.apply(Incremental.scala:32)
at sbt.inc.Incremental$.manageClassfiles(Incremental.scala:41)
at sbt.inc.Incremental$.compile(Incremental.scala:32)
at sbt.inc.IncrementalCompile$.apply(Compile.scala:26)
at sbt.compiler.AggressiveCompile.compile2(AggressiveCompile.scala:150)
at sbt.compiler.AggressiveCompile.compile1(AggressiveCompile.scala:70)
at sbt.compiler.AggressiveCompile.apply(AggressiveCompile.scala:45)
at sbt.compiler.IC$.compile(IncrementalCompiler.scala:22)
at scala.tools.eclipse.buildmanager.sbtintegration.EclipseSbtBuildManager.runCompiler(EclipseSbtBuildManager.scala:138)
at scala.tools.eclipse.buildmanager.sbtintegration.EclipseSbtBuildManager.update(EclipseSbtBuildManager.scala:129)
at scala.tools.eclipse.buildmanager.sbtintegration.EclipseSbtBuildManager.build(EclipseSbtBuildManager.scala:175)
at scala.tools.eclipse.ScalaProject.build(ScalaProject.scala:581)
at scala.tools.eclipse.ScalaBuilder.build(ScalaBuilder.scala:129)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:726)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:239)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:292)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:295)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:351)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:374)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
Caused by: java.lang.ClassNotFoundException: HWND
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 73 more
Scala plugin version: 4.0.0.nightly-2_11-201312140620-1d0a313
Scala compiler version: 2.11.0.v20131212-075740-73cddba169
Scala library version: 2.11.0.v20131212-075740-73cddba169
Eclipse version: 4.2.2.v201302041200
Leave a comment
file:c_L_8Czwur46y6acwqjQYw
Java and Scala projects reproducing the problem
Java and Scala projects reproducing the problem
on 2014-10-11 06:42 *
By Iulian Dragos
Sbt incremental compiler bug: https://github.com/sbt/sbt/issues/117