This page is no longer maintained — Please continue to the home page at

getSimpleName missbehaves for case classes

No replies
Razvan Cojocaru 3
Joined: 2010-07-28,
User offline. Last seen 42 years 45 weeks ago.

I found a June thread but with no reply… I remember having this issue myself in the past, so here goes for future reference.


$ scala

Failed to created JLineReader: java.lang.NoClassDefFoundError: Could not initialize class org.fusesource.jansi.internal.


Falling back to SimpleReader.

Welcome to Scala version (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_22).

Type in expressions to have them evaluated.

Type :help for more information.


scala> case class C

warning: there were 1 deprecation warnings; re-run with -deprecation for details

defined class C



java.lang.InternalError: Malformed class name

        at java.lang.Class.getSimpleName(

        at $anonfun$1.apply(<console>:10)

        at $anonfun$1.apply(<console>:10)

        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:194)

        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:194)

        at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:34)

        at scala.collection.mutable.ArrayOps.foreach(ArrayOps.scala:38)

        at scala.collection.TraversableLike$


        at .<init>(<console>:10)

        at .<clinit>(<console>)

        at .<init>(<console>:11)

        at .<clinit>(<console>)

        at $print(<console>)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(

        at java.lang.reflect.Method.invoke(









Well, the reason is the REPL mangles some of the types and makes them look like: $line4.$read$$iw$$iw$C AND Java.lang.Class really doesn’t like that.


… meh, 2 more hours spent chasing dollars… or rather dollar signs… oh, well. The thing is you have no way of figuring that out without some medieval debugging


Anyways, it makes looking for classnames rather painful. This after dealing with a bunch of add-ons like MODULE$ or readResolve.


If you’re browsing class hierarchies via reflection, I strongly suggest you rather Snakk them, which works for now with both Java/Scala, compiled code and interpreted:


case class C4 { val c="wow" }
case class C3 { val c=C4() }
case class C2 { val c=C3() }
case class C1 { val c=C2() }

razie.Snakk.bean(C1()) \\ "C4" \@@ "c"​



Happy snakking!






Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland