Aladdin - Scala Bugtracking
[#1028] project: compiler priority: low category: bug
submitter assigned to status date submitted
Sean Iulian won't fix 2007-03-28 11:16:21.0
subject Inner class names not up to spec?
code
package test;
object Go {
  def main(args : Array[String]) : Unit = 
    (new Hello).getClass.getSimpleName;
  class Hello;
}
what happened
On run:
Exception in thread "main" java.lang.InternalError: Malformed class name
	at java.lang.Class.getSimpleName(Class.java:1129)
	at test.Go$.main(Go.scala:4)
	at test.Go.main(Go.scala)
The code in Class.java:
if (length < 1 || simpleName.charAt(0) != '$')
  throw new InternalError("Malformed class name");
what expected
[back to overview]
Changes of this bug report
Iulian  edited on  2007-04-02 10:29:50.0
They are up to spec (the JVM spec), but break Java language compatibility :-/ This is a bit twisted, but the idea is that the reflection API assumes a certain name mangling (namely, that an inner class name is formed by the binary name of it's enclosing class, a '$', and the simple name of that class). Sun's JDK uses this to decide the implemented inner name, while IBM uses the proper field in the InnerClass attribute (and runs without error).
In most cases, Sun's scheme works, but we do have cases when there are more than one '$', or none. In this case, it is the top-level object Go, which is encoded as Go$, which is listed as the outer class of Hello. Then, the full name (Go$Hello) - the outer class name (Go$) results in Hello, but according to the name scheme, it should have been $Hello.
Iulian  edited on  2007-05-01 09:57:04.0