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

Compiler fails to parse Java class files with missing annotations #7751

Open
scabug opened this issue Aug 14, 2013 · 15 comments

Comments

@scabug
Copy link

commented Aug 14, 2013

Attempting to use the Guava cache package without the JSR-305 and JSR-330 annotations in the classpath results in some rather strange error messages:

warning: Class javax.annotation.Nullable not found - continuing with a stub.
warning: Caught: java.lang.NullPointerException while parsing annotations in /home/users/alex/.m2/repository/com/google/guava/guava/14.0.1/guava-14.0.1.jar(com/google/common/cache/LocalCache.class)
error: error while loading LocalCache, class file '/home/users/alex/.m2/repository/com/google/guava/guava/14.0.1/guava-14.0.1.jar(com/google/common/cache/LocalCache.class)' is broken
(class java.lang.RuntimeException/bad constant pool tag 9 at byte 125)
warning: Class javax.annotation.CheckReturnValue not found - continuing with a stub.
warning: Caught: java.lang.NullPointerException while parsing annotations in /home/users/alex/.m2/repository/com/google/guava/guava/14.0.1/guava-14.0.1.jar(com/google/common/cache/CacheBuilder.class)
error: error while loading CacheBuilder, class file '/home/users/alex/.m2/repository/com/google/guava/guava/14.0.1/guava-14.0.1.jar(com/google/common/cache/CacheBuilder.class)' is broken
(class java.lang.RuntimeException/bad constant pool index: 0 at pos: 15184)
/home/users/alex/code/projects/java/scala-safe-cast/src/main/scala/scalaSafeCast/package.scala:66: error: value build is not a member of com.google.common.cache.CacheBuilder[Object,Object]
possible cause: maybe a semicolon is missing before `value build'?
		.build(CacheLoader.from(new com.google.common.base.Function[ClassSymbol, immutable.Seq[MethodSymbol]] {
                 ^
warning: Class javax.annotation.Nullable not found - continuing with a stub.
warning: Caught: java.lang.NullPointerException while parsing annotations in /home/users/alex/.m2/repository/com/google/guava/guava/14.0.1/guava-14.0.1.jar(com/google/common/cache/Cache.class)
error: error while loading Cache, class file '/home/users/alex/.m2/repository/com/google/guava/guava/14.0.1/guava-14.0.1.jar(com/google/common/cache/Cache.class)' is broken
(class java.lang.RuntimeException/bad constant pool index: 1025 at pos: 1213)
warning: Class javax.annotation.Nullable not found - continuing with a stub.
warning: Caught: java.lang.NullPointerException while parsing annotations in /home/users/alex/.m2/repository/com/google/guava/guava/14.0.1/guava-14.0.1.jar(com/google/common/base/Function.class)
error: error while loading Function, class file '/home/users/alex/.m2/repository/com/google/guava/guava/14.0.1/guava-14.0.1.jar(com/google/common/base/Function.class)' is broken
(class java.lang.RuntimeException/bad constant pool index: 0 at pos: 479)

At a minimum, the compiler should explain that compilation against Java class files with missing annotations is not allowed, and not emit all of those other strange messages.

It would be preferable, however, for the compiler to proceed without the missing annotations, like the Java compiler does.

It seems that others have run into this problem as well, but I couldn't find any mention of it in the issue tracker.

@scabug

This comment has been minimized.

Copy link
Author

commented Aug 14, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7751?orig=1
Reporter: Alex Hvostov (argv)
Affected Versions: 2.10.2
See #5420, #7551, #8442, #7439

@scabug

This comment has been minimized.

Copy link
Author

commented Aug 14, 2013

@retronym said:
Can you please post a sample project that includes the dependency and source file to trigger this? We've done some work in 2.11.x to improve the situation.

@scabug

This comment has been minimized.

Copy link
Author

commented Aug 14, 2013

@retronym said:
Perhaps related to #7551

@scabug

This comment has been minimized.

Copy link
Author

commented Aug 15, 2013

@retronym said:
I've cobbled together a test case, which has indeed progressed in 2.11.

% tail build.sbt test.scala
==> build.sbt <==
scalaVersion := "2.11.0-M4"

libraryDependencies +=  "com.google.guava" % "guava" % "14.0.1"


==> test.scala <==
object Test {
  def foo(c: com.google.common.cache.CacheBuilder[_, _]) {}
}

% sbt -scala-home "$(scala-hash -h a954321)" compile
[info] a954321 => /Users/jason/usr/scala-v2.11.0-M3-153-ga954321
Detected sbt version 0.13.0-RC2
Using /Users/jason/.sbt/0.13.0-RC2 as sbt dir, -sbt-dir to override.
[YourKit Java Profiler 11.0.9] Log file: /Users/jason/.yjp/log/14872.log
[info] Loading project definition from /Users/jason/code/scratch3/project
[info] Set current project to scratch3 (in build file:/Users/jason/code/scratch3/)
[info] Defining {.}/*:scalaHome
[info] The new value will be used by *:allDependencies, *:ivyConfigurations and 4 others.
[info] 	Run `last` for details.
[info] Reapplying settings...
[info] Set current project to scratch3 (in build file:/Users/jason/code/scratch3/)
[info] Updating {file:/Users/jason/code/scratch3/}scratch3...
[info] Resolving com.google.guava#guava;14.0.1 ...
[info] Done updating.
[info] Compiling 1 Scala source and 1 Java source to /Users/jason/code/scratch3/target/scala-2.11.0-M4/classes...
[info] 'compiler-interface' not yet compiled for Scala 2.11.0-20130613-115152-a954321682. Compiling...
[info]   Compilation completed in 15.208 s
[warn] Class javax.annotation.Nullable not found - continuing with a stub.
[warn] Class javax.annotation.Nullable not found - continuing with a stub.
[warn] Class javax.annotation.Nullable not found - continuing with a stub.
[warn] Class javax.annotation.Nullable not found - continuing with a stub.
[warn] Class javax.annotation.Nullable not found - continuing with a stub.
[warn] Class javax.annotation.CheckReturnValue not found - continuing with a stub.
[warn] 6 warnings found
[success] Total time: 18 s, completed Aug 15, 2013 9:48:36 AM


% sbt -scala-home "$(scala-hash -h a954321~1)" compile
[info] a954321~1 => /Users/jason/usr/scala-v2.11.0-M3-152-g5312d63
Detected sbt version 0.13.0-RC2
Using /Users/jason/.sbt/0.13.0-RC2 as sbt dir, -sbt-dir to override.
[YourKit Java Profiler 11.0.9] Log file: /Users/jason/.yjp/log/14931.log
[info] Loading project definition from /Users/jason/code/scratch3/project
[info] Set current project to scratch3 (in build file:/Users/jason/code/scratch3/)
[info] Defining {.}/*:scalaHome
[info] The new value will be used by *:allDependencies, *:ivyConfigurations and 4 others.
[info] 	Run `last` for details.
[info] Reapplying settings...
[info] Set current project to scratch3 (in build file:/Users/jason/code/scratch3/)
[info] Compiling 1 Scala source and 1 Java source to /Users/jason/code/scratch3/target/scala-2.11.0-M4/classes...
[info] 'compiler-interface' not yet compiled for Scala 2.11.0-20130605-180002-5312d63055. Compiling...
[info]   Compilation completed in 16.349 s
[warn] Class javax.annotation.Nullable not found - continuing with a stub.
[warn] Caught: java.lang.NullPointerException while parsing annotations in /Users/jason/.ivy2/cache/com.google.guava/guava/bundles/guava-14.0.1.jar(com/google/common/cache/LocalCache.class)
[error] bad constant pool tag ${in.buf(start)} at byte $start
[error] uncaught exception during compilation: FatalError("
...


/code/scratch3 sbt -scala-home "$(scala-hash -h v2.10.2)" compile
[info] v2.10.2 => /Users/jason/usr/scala-v2.10.2-0-g60d462e
Detected sbt version 0.13.0-RC2
Using /Users/jason/.sbt/0.13.0-RC2 as sbt dir, -sbt-dir to override.
[YourKit Java Profiler 11.0.9] Log file: /Users/jason/.yjp/log/14990.log
[info] Loading project definition from /Users/jason/code/scratch3/project
[info] Set current project to scratch3 (in build file:/Users/jason/code/scratch3/)
[info] Defining {.}/*:scalaHome
[info] The new value will be used by *:allDependencies, *:ivyConfigurations and 4 others.
[info] 	Run `last` for details.
[info] Reapplying settings...
[info] Set current project to scratch3 (in build file:/Users/jason/code/scratch3/)
[info] Compiling 1 Scala source and 1 Java source to /Users/jason/code/scratch3/target/scala-2.11.0-M4/classes...
[info] 'compiler-interface' not yet compiled for Scala 2.10.2-20130530-074427-60d462ef6e. Compiling...
[info]   Compilation completed in 15.238 s
[warn] Class javax.annotation.Nullable not found - continuing with a stub.
[warn] Caught: java.lang.NullPointerException while parsing annotations in /Users/jason/.ivy2/cache/com.google.guava/guava/bundles/guava-14.0.1.jar(com/google/common/cache/LocalCache.class)
[error] error while loading LocalCache, class file '/Users/jason/.ivy2/cache/com.google.guava/guava/bundles/guava-14.0.1.jar(com/google/common/cache/LocalCache.class)' is broken
[error] (class java.lang.RuntimeException/bad constant pool tag 9 at byte 125)
[warn] Class javax.annotation.CheckReturnValue not found - continuing with a stub.
[warn] Caught: java.lang.NullPointerException while parsing annotations in /Users/jason/.ivy2/cache/com.google.guava/guava/bundles/guava-14.0.1.jar(com/google/common/cache/CacheBuilder.class)
[error] error while loading CacheBuilder, class file '/Users/jason/.ivy2/cache/com.google.guava/guava/bundles/guava-14.0.1.jar(com/google/common/cache/CacheBuilder.class)' is broken
[error] (class java.lang.RuntimeException/bad constant pool index: 0 at pos: 15184)
[warn] four warnings found
[error] two errors found
[error] (compile:compile) Compilation failed
[error] Total time: 16 s, completed Aug 15, 2013 9:50:56 AM
@scabug

This comment has been minimized.

Copy link
Author

commented Nov 13, 2013

Kris Nuttycombe (nuttycom) said (edited on Nov 13, 2013 8:53:41 PM UTC):
A possible workaround: I ran into this issue when pruning dependencies from a project. Interestingly, the pruning step that first revealed the error was removing this dependency:

"com.google.code.findbugs" % "jsr305" % "2.0.0",

And reintroducing the dependency fixed the error, though I've not done any detailed experimentation to determine why.

And, now actually reading to the top of the ticket, I realize that this was already know. Sorry for the noise.

@scabug

This comment has been minimized.

Copy link
Author

commented Jan 31, 2014

Stevo Slavic (sslavic) said:
I've just encountered same issue with Spring 4.0.1.RELEASE, Spring-Scala 1.0.0.RC1, Scala 2.10.3, sbt 0.13.1 and JDK 1.7 update 45. Spring 4.0.x is using a JDK 8 annotation java.lang.annotation.Repetable (see here). Compilation with Scala, of class which makes use of Spring annotation annotated with @Repeatable, fails:

...
[info] Compiling 15 Scala sources to C:\foo\bar\target\scala-2.10\classes...
[error] Class java.lang.annotation.Repeatable not found - continuing with a stub.
[error] Caught: java.lang.NullPointerException while parsing annotations in C:\Users\stevo.slavic\.ivy2\cache\org.springframework\spring-context\jars\spring-context-4.0.1.RELEASE.jar(org/springframework/context/annotation/PropertySource.class)
[error] two errors found
[error] (compile:compile) Compilation failed
@scabug

This comment has been minimized.

Copy link
Author

commented Feb 8, 2014

Sean Owen (srowen) said:
FWIW I am also seeing apparently the same problem in the following situation, and I have a work-around for the situation, which might help others or highlight a possible improvement to the scala compiler:

  • Project depends on hadoop-client
  • hadoop-common depends on commons-logging
  • We exclude commons-logging dependency from hadoop-client and instead replace it with SLF4J's shim jcl-over-slf4j, a drop-in API replacement

We get:

[WARNING] Class org.apache.commons.logging.Log not found - continuing with a stub.
[ERROR] error while loading FileInputFormat, class file '/Users/srowen/.m2/repository/org/apache/hadoop/hadoop-core/1.0.4/hadoop-core-1.0.4.jar(org/apache/hadoop/mapred/FileInputFormat.class)' is broken

The class is available in jcl-over-slf4j, but is marked as "runtime" dependency since it is not used directly, and not needed -- by the likes of javac at least -- at compile time.

Changing the scope to "compile" makes it work, presumably because then scalac sees it, and it seems that without seeing it, this error occurs. I don't know if it's realistic, but ideally the behavior would match that of javac, which does not need knowledge of a dependency like this.

@scabug

This comment has been minimized.

Copy link
Author

commented Feb 8, 2014

@retronym said:
We've improved this a bit in Scala 2.10.4 (or was it 2.10.3?) What version are you testing with?

You can use scope = provided to keep it on the compile time classpath but exclude as a runtime/transitive dependency of your project.

@scabug

This comment has been minimized.

Copy link
Author

commented Feb 8, 2014

Sean Owen (srowen) said:
I'm using 2.10.3. The thing is we want it available exactly at runtime, and not compile time -- the opposite. It's not a big deal to use compile scope and then simply not actually use it directly.

@scabug

This comment has been minimized.

Copy link
Author

commented Feb 8, 2014

@retronym said:
I found the change I was thinking of. It is #7439, which is fixed in 2.10.4.

Our "stub symbol" handling regressed badly before that fix. We still run into problems with it, but I would be interested to hear how your scenario is handled in 2.10.4-RC2.

@scabug

This comment has been minimized.

Copy link
Author

commented May 10, 2014

Sunghyouk Bae (debop) said (edited on May 10, 2014 10:01:25 AM UTC):
It has occur in 2.10.3, 2.10.4, 2.11.0 in compile time.

I use spring 4 @scheduled that use @repeatable in JDK 8

@scabug

This comment has been minimized.

Copy link
Author

commented May 10, 2014

@retronym said:
I also fixed #8442 in the upcoming 2.11.1 / 2,10.5 which manifests in the same way.

@scabug

This comment has been minimized.

Copy link
Author

commented Aug 15, 2016

Michael Ahlers (michaelahlers) said (edited on Aug 15, 2016 12:43:39 AM UTC):
Ran into this with Scala 2.11.8. Regression? [-A workaround- Compiler warnings are solved by including Google's JSR-305 library (as described in #8978) fixes this which may be helpful to projects with "-Xfatal-warnings".

@scabug

This comment has been minimized.

Copy link
Author

commented Aug 15, 2016

@retronym said:
[~michaelahlers] Could you provide some details on how to reproduce this? What stack trace did you see?

@scabug

This comment has been minimized.

Copy link
Author

commented Aug 15, 2016

Michael Ahlers (michaelahlers) said:
@retronym, I looked before I leapt. It's while I was making a sample project I noticed my error came from "-Xfatal-warnings". So… non-issue. Sorry for the noise!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.