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

"bad constant pool index" when compiling against Java class compiled by the Eclipse Java compiler #7002

Closed
scabug opened this issue Jan 21, 2013 · 4 comments

Comments

@scabug
Copy link

scabug commented Jan 21, 2013

Original report (Scala IDE): #1001402

Twin issue reported against Eclipse: #398657

Scalac crashes when trying to open a Java class, with annotations, compiled by the Eclipse Java compiler.

The Java code is the following:

package ide.issue.session;

import java.util.HashMap;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonTypeInfo;

@JsonIgnoreProperties(ignoreUnknown=true)
public class JavaClass {

	@JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.PROPERTY, property="@class")
    protected HashMap<String, Object> content = new HashMap<String, Object>();

    public void foo() {
		
    }
}

It depends on "org.codehaus.jackson" % "jackson-core-asl" % "1.9.4", also available here.

I attached a zip with the result of the compilation with the Eclipse Java compiler.

A Scala test class:

package ide.issue.security

import ide.issue.session.JavaClass


class ScalaTest {
  def test(){
    val j= new JavaClass()
  }
}

The error:

$ scalac -classpath ../jackson-core-asl-1.9.4.jar:../t1402.jar ScalaTest.scala 
error: error while loading JsonTypeInfo$Id, class file '../jackson-core-asl-1.9.4.jar(org/codehaus/jackson/annotate/JsonTypeInfo$Id.class)' is broken
(class java.lang.UnsupportedOperationException/addChild inapplicable for <none>)
warning: Caught: java.lang.AssertionError: assertion failed: 
     while compiling: ScalaTest.scala
        during phase: typer
     library version: version 2.10.0
    compiler version: version 2.10.0
  reconstructed args: -classpath ../jackson-core-asl-1.9.4.jar:../t1402.jar

  last tree to typer: Ident(JavaClass)
              symbol: <none> (flags: sealed abstract)
   symbol definition: <none>
       symbol owners: 
      context owners: value j -> method test -> class ScalaTest -> package security

== Enclosing template or block ==

Block(
  ValDef( // val j: <?>
    <locked>
    "j"
    <tpt>
    Apply(
      new JavaClass."<init>"
      Nil
    )
  )
  ()
)

org.codehaus.jackson.annotate.JsonTypeInfo$Id while parsing annotations in ../t1402.jar(ide/issue/session/JavaClass.class)
error: error while loading JavaClass, class file '../t1402.jar(ide/issue/session/JavaClass.class)' is broken
(class java.lang.RuntimeException/bad constant pool index: 3840 at pos: 710)
ScalaTest.scala:8: error: ide.issue.session.JavaClass does not have a constructor
    val j= new JavaClass()
           ^
one warning found
three errors found

If the Java class is compiled with javac, scalac is working fine.

@scabug
Copy link
Author

scabug commented Jan 21, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7002?orig=1
Reporter: @skyluc
Affected Versions: 2.9.3-RC2, 2.10.0
Attachments:

  • t1402.jar (created on Jan 21, 2013 5:04:12 PM UTC, 849 bytes)

@scabug
Copy link
Author

scabug commented Jan 22, 2013

@skyluc said:
It kind of look like a scalac problem.

I tested the same jar with javac, and it compiles and run without any problem.

Test class:

package ide.issue.security;

import ide.issue.session.JavaClass;

public class JavaTest {
	
	public static void main(String[] args) {
		new JavaTest().test();
	}
	
	public void test() {
		JavaClass j= new JavaClass();
		j.toString();
	}
}

@scabug
Copy link
Author

scabug commented Jan 29, 2013

@skyluc said:
The Eclipse Java compiler team found a problem in the classfiles they were generating. It has been fixed in their code base. The fix will be available in the next release version (kepler - 4.3).

One comment which might be interesting for the Scala compiler:

[comment #10|https://bugs.eclipse.org/bugs/show_bug.cgi?id=398657#c10]
I have to admit that I am pretty disappointed by the error reported by the scala compiler:

org.codehaus.jackson.annotate.JsonTypeInfo$Id while parsing annotations in ../t1402.jar(ide/issue/session/JavaClass.class)
error: error while loading JavaClass, class file '../t1402.jar(ide/issue/session/JavaClass.class)' is broken
(class java.lang.RuntimeException/bad constant pool index: 3840 at pos: 710)
ScalaTest.scala:8: error: ide.issue.session.JavaClass does not have a constructor

This is completely misleading. The problem is a missing inner class info. Not a problem with the constant pool. A better error would have help to diagnose this issue quicker.

@scabug scabug closed this as completed Jan 29, 2013
@scabug
Copy link
Author

scabug commented Jan 29, 2013

@retronym said:
Heh, it's kind of funny that Eclipse is sending up broken class files and breaking us for once; I thought we had exclusive rights do the reverse!

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

No branches or pull requests

1 participant