Skip to content
This repository was archived by the owner on Feb 20, 2019. It is now read-only.
This repository was archived by the owner on Feb 20, 2019. It is now read-only.

error: cannot find class or module with type name 'scala.collection.immutable.ListMap.Node' #377

Open
@richard-jepps

Description

@richard-jepps

This might help somebody else as it seems like "game over" if you hit this as a library user, but it's fairly easy to work around.

This example code:

import scala.collection.immutable.HashMap

object ListMapNode {
  def main(args: Array[String]): Unit = {
    import scala.pickling.Defaults._
    import scala.pickling.json._

    val broken = HashMap(new BadHashCode(0) -> 0, new BadHashCode(1) -> 1)

    broken.pickle
  }
}

class BadHashCode(unique: Int) {
  override def hashCode(): Int = 666
}

... produces this exception:

Exception in thread "main" java.lang.RuntimeException: error: cannot find class or module with type name 'scala.collection.immutable.ListMap.Node' full type string: 'scala.collection.immutable.ListMap.Node' at scala.sys.package$.error(package.scala:27) at scala.pickling.internal.package$.liftedTree1$1(package.scala:71) at scala.pickling.internal.package$.typeFromString(package.scala:66) at scala.pickling.FastTypeTag$$anon$2.tpe$lzycompute(FastTags.scala:141) at scala.pickling.FastTypeTag$$anon$2.tpe(FastTags.scala:141) at scala.pickling.runtime.RuntimePickler.pickleInto(RuntimePickler.scala:163) at scala.pickling.runtime.RuntimePickler$DefaultLogic.pickleLogic(RuntimePickler.scala:101) at scala.pickling.runtime.RuntimePickler$Logic$$anonfun$run$1.apply(RuntimePickler.scala:85) at scala.pickling.runtime.RuntimePickler$Logic$$anonfun$run$1.apply(RuntimePickler.scala:84) at scala.pickling.json.JSONPickleBuilder$$anonfun$putField$1.apply(JSONPickleFormat.scala:151) at scala.pickling.json.JSONPickleBuilder$$anonfun$putField$1.apply(JSONPickleFormat.scala:147) at scala.pickling.json.JSONPickleBuilder.ignoringSharedRef(JSONPickleFormat.scala:146) at scala.pickling.json.JSONPickleBuilder.putField(JSONPickleFormat.scala:147) at scala.pickling.runtime.RuntimePickler$Logic.run(RuntimePickler.scala:84) at scala.pickling.runtime.RuntimePickler$$anon$2$$anonfun$putFields$1.apply(RuntimePickler.scala:200) at scala.pickling.runtime.RuntimePickler$$anon$2$$anonfun$putFields$1.apply(RuntimePickler.scala:200) at scala.collection.immutable.List.foreach(List.scala:381) at scala.pickling.runtime.RuntimePickler$$anon$2.putFields(RuntimePickler.scala:200) at scala.pickling.runtime.RuntimePickler$$anon$2.pickle(RuntimePickler.scala:210) at org.reductio.scratch.ListMapNode$ScalaCollectionImmutableHashMap$u005BorgReductioScratchBadHashCode$u002CscalaInt$u005DPickler$macro$1$2$.pickle(ListMapNode.scala:15) at org.reductio.scratch.ListMapNode$ScalaCollectionImmutableHashMap$u005BorgReductioScratchBadHashCode$u002CscalaInt$u005DPickler$macro$1$2$.pickle(ListMapNode.scala:15) at scala.pickling.functions$.pickleInto(functions.scala:26) at scala.pickling.functions$.pickle(functions.scala:14) at scala.pickling.PickleOps.pickle(Ops.scala:9) at org.reductio.scratch.ListMapNode$.main(ListMapNode.scala:15) at org.reductio.scratch.ListMapNode.main(ListMapNode.scala) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)

I'm using 0.11.x commit b3a2ad1

Unfortunately the stack trace is truncated within the pickling code, but the line that causes the error is line 68 in the scala.pickling package object:

mirror.staticClass(typename)

... which fails at runtime when looking up a protected class nested inside a public class.

This specific issue is straightforward to workaround, either:

  • Use Map instead of HashMap, or ...
  • Make sure that your key class produces unique hash codes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions