Scala error: class file is damaged, invalid constant pool index

I am trying to call the Selenium Java libraries from Scala. I am using the Scala IDE (Eclipse) and Scala 2.10.2. What causes a compiler error?

error while loading Function, class file '/Dev/selenium-2.35.0/libs/guava- 14.0.jar(com/google/common/base/Function.class)' is broken (class java.lang.RuntimeException/bad constant pool index: 0 at pos: 479) 

Sometimes I fix the errors of a broken class file by adding more cans - cans that javac would not need to see, but apparently scalac does. But in this case, I do not know what other banks I can add.

+7
source share
2 answers

Found the answer. This is caused by this: https://code.google.com/p/guava-libraries/issues/detail?id=1095 . The error disappeared when I added the jsr305 jar.

+4
source share

RobN's answer is correct, but I thought I would write a slightly longer answer with my own experience. This is due to this issue and discussions of the problems of Guava 776 and 1095 mentioned by RobN.

I had the same problem trying to access

 com.google.common.io.BaseEncoding.base64() 

Eclipse claims that the base64 element does not exist and Gradle build throws an error in the question:

 [ant:scalac] error: error while loading BaseEncoding, class file '.../guava-16.0.jar(com/google/common/io/BaseEncoding.class)' is broken 

The error is caused by an optional dependency on some annotations in Guava pom.xml . As explained in this answer , the Java compiler ignores annotations for which the corresponding class file was not found, but the Scala compiler requires compromise.

Explicitly adding a dependency, which is optional, should solve the problem.

In this particular case, Guava pom.xml has the following additional dependency and adding dependency declarations below to your project will solve the problem:

Gradle:

 compile 'com.google.code.findbugs:jsr305:2.0.2' 

Maven:

 <dependency> <groupId>com.google.code.findbugs</groupId> <artifactId>jsr305</artifactId> <version>2.0.2</version> </dependency> 
+4
source share

All Articles