Skip to content
Permalink
Browse files

SI-7556 Fix runtime reflection involving ScalaLongSignature

Scala type information is stored in classfiles in encoded in a String
in the ScalaSignature annotation. When it is too big for a single
String, it is split into an array of Strings in a different annotation,
ScalaLongSignature.

The enclosed test, with a class containing 3000 methods, uses the latter.
It exposes a bug in the way runtime reflection decodes that data.

It must concatentate and *then* decode, rather that the other way around.
  • Loading branch information...
@retronym
retronym committedJun 5, 2013
1 parent 681f207 commit 28c5f730820dd76d85c2f6f81bf60aae03aabe41
@@ -567,15 +567,10 @@ private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUni
loadBytes[Array[String]]("scala.reflect.ScalaLongSignature") match {
case Some(slsig) =>
info(s"unpickling Scala $clazz and $module with long Scala signature")
val byteSegments = slsig map (_.getBytes)
val lens = byteSegments map ByteCodecs.decode
val bytes = Array.ofDim[Byte](lens.sum)
var len = 0
for ((bs, l) <- byteSegments zip lens) {
bs.copyToArray(bytes, len, l)
len += l
}
unpickler.unpickle(bytes, 0, clazz, module, jclazz.getName)
val encoded = slsig flatMap (_.getBytes)
val len = ByteCodecs.decode(encoded)
val decoded = encoded.take(len)
unpickler.unpickle(decoded, 0, clazz, module, jclazz.getName)
case None =>
// class does not have a Scala signature; it's a Java class
info("translating reflection info for Java " + jclazz) //debug
@@ -0,0 +1,2 @@
class annotations: List(scala.reflect.ScalaLongSignature)
3001 decls via runtime reflection
@@ -0,0 +1,11 @@
import scala.reflect.runtime.universe._

object Test {
def main(args: Array[String]) {
val mc = new MegaClass
val anns = mc.getClass.getAnnotations.map(_.annotationType.getName).toList.sorted
println(s"class annotations: $anns")
val N = typeTag[MegaClass].tpe.declarations.size // was: error reading Scala signature of MegaClass: 65935
println(s"$N decls via runtime reflection")
}
}
Oops, something went wrong.

0 comments on commit 28c5f73

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.