Skip to content

Commit d2cffb9

Browse files
lrytzadriaanm
authored andcommitted
deserializeLambda should not use encoded class name
`javaBinaryName` returns the internal name of a class. Also used in BTypesFromsymbols.classBTypeFromSymbol. Weirdly, this was discovered due to a bizarre osgi bnd error: ``` [bnd] # addAll '/Users/luc/scala/scala/build/pack/lib/scala-library.jar' with :, [bnd] # addAll '/Users/luc/scala/scala/build/osgi/scala-library.bnd' with , [bnd] 1 ERRORS [bnd] The default package '.' is not permitted by the Import-Package syntax. [bnd] This can be caused by compile errors in Eclipse because Eclipse creates [bnd] valid class files regardless of compile errors. [bnd] The following package(s) import from the default package [scala.collection.generic, scala.sys.process, scala.collection.parallel.mutable, scala.util, scala.collection.parallel.immutable, scala.reflect, scala.concurrent.impl, scala.util.hashing, scala.collection.parallel, scala.collection.convert, scala.io, scala, scala.collection.concurrent, scala.util.control, scala.beans, scala.concurrent.duration, scala.collection, scala.runtime, scala.math, scala.collection.mutable, scala.concurrent, scala.sys, scala.collection.immutable, scala.ref, scala.util.matching] [bnd] /Users/luc/scala/scala/build/osgi/scala-library.bnd: bnd failed ``` Lukas diagnosed it as a problem of the generated `$deserializeLambda$` function: One example is `scala/App$class`. Its bytecode contains this: ``` private static synthetic $deserializeLambda$(Ljava/lang/invoke/SerializedLambda;)Ljava/lang/Object; GETSTATIC scala$divApp$class.$deserializeLambdaCache$ : Ljava/util/Map; [...] ``` so it's a static field read of a top-level class. `$div` should obviously be `/` (which this commit rectifies)
1 parent 373db1e commit d2cffb9

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/compiler/scala/tools/nsc/backend/jvm/BCodeHelpers.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,8 @@ abstract class BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
715715
{
716716
val mv = cw.visitMethod(ACC_PRIVATE + ACC_STATIC + ACC_SYNTHETIC, "$deserializeLambda$", "(Ljava/lang/invoke/SerializedLambda;)Ljava/lang/Object;", null, null)
717717
mv.visitCode()
718-
mv.visitFieldInsn(GETSTATIC, clazz.javaBinaryName.encoded, "$deserializeLambdaCache$", "Ljava/util/Map;")
718+
// javaBinaryName returns the internal name of a class. Also used in BTypesFromsymbols.classBTypeFromSymbol.
719+
mv.visitFieldInsn(GETSTATIC, clazz.javaBinaryName.toString, "$deserializeLambdaCache$", "Ljava/util/Map;")
719720
mv.visitVarInsn(ASTORE, 1)
720721
mv.visitVarInsn(ALOAD, 1)
721722
val l0 = new asm.Label()
@@ -725,7 +726,7 @@ abstract class BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
725726
mv.visitMethodInsn(INVOKESPECIAL, "java/util/HashMap", "<init>", "()V", false)
726727
mv.visitVarInsn(ASTORE, 1)
727728
mv.visitVarInsn(ALOAD, 1)
728-
mv.visitFieldInsn(PUTSTATIC, clazz.javaBinaryName.encoded, "$deserializeLambdaCache$", "Ljava/util/Map;")
729+
mv.visitFieldInsn(PUTSTATIC, clazz.javaBinaryName.toString, "$deserializeLambdaCache$", "Ljava/util/Map;")
729730
mv.visitLabel(l0)
730731
mv.visitFrame(asm.Opcodes.F_APPEND,1, Array("java/util/Map"), 0, null)
731732
mv.visitMethodInsn(INVOKESTATIC, "java/lang/invoke/MethodHandles", "lookup", "()Ljava/lang/invoke/MethodHandles$Lookup;", false)

0 commit comments

Comments
 (0)