java.lang.ClassCastException: scala.collection.immutable.$colon$colon cannot be cast to com.mongodb.casbah.commons.MongoDBList

JIRA | Brandon Hudgeons | 3 years ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    {code} scala> val test = testcollections.testcoll test: com.mongodb.casbah.MongoCollection = testtest scala> import com.mongodb.casbah.Imports._ import com.mongodb.casbah.Imports._ scala> test.save(MongoDBObject("list" -> List("one", "two", "three"))) // save a list to mongodb res1: com.mongodb.WriteResult = N/A scala> val o = test.findOne.get // get back the thing we just saved o: test.T = { "_id" : { "$oid" : "52f559c63004ae5f4863ef4e"} , "list" : [ "one" , "two" , "three"]} scala> o.getAs[MongoDBList]("list") // get the list out res2: Option[com.mongodb.casbah.Imports.MongoDBList] = Some([ "one" , "two" , "three"]) scala> o.getAs[MongoDBList]("list").get.toList // turn it from Option[MongoDBList] to a scala List[Any] res3: List[Any] = List(one, two, three) scala> o.getAs[MongoDBList]("list").map(_.toList) // same thing, but use map so we get an Option[List[Any]] res8: Option[List[Any]] = Some(List(one, two, three)) scala> o += "list" -> List("one", "two", "three") // set the "list" again, the same way we did before res4: com.mongodb.casbah.commons.MongoDBObject = { "_id" : { "$oid" : "52f559c63004ae5f4863ef4e"} , "list" : [ "one" , "two" , "three"]} scala> o.getAs[MongoDBList]("list") // get the list out again res5: Option[com.mongodb.casbah.Imports.MongoDBList] = Some(List(one, two, three)) scala> o.getAs[MongoDBList]("list").get.toList // same thing we did before ... works fine. res6: List[Any] = List(one, two, three) scala> o.getAs[MongoDBList]("list").map(_.toList) // same thing we did before ... DOH! java.lang.ClassCastException: scala.collection.immutable.$colon$colon cannot be cast to com.mongodb.casbah.commons.MongoDBList at $anonfun$1.apply(<console>:15) at scala.Option.map(Option.scala:145) at .<init>(<console>:15) at .<clinit>(<console>) at .<init>(<console>:7) at .<clinit>(<console>) at $print(<console>) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:734) at scala.tools.nsc.interpreter.IMain$Request.loadAndRun(IMain.scala:983) at scala.tools.nsc.interpreter.IMain.loadAndRunReq$1(IMain.scala:573) at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:604) at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:568) at scala.tools.nsc.interpreter.ILoop.reallyInterpret$1(ILoop.scala:756) at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:801) at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:713) at scala.tools.nsc.interpreter.ILoop.processLine$1(ILoop.scala:577) at scala.tools.nsc.interpreter.ILoop.innerLoop$1(ILoop.scala:584) at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:587) at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply$mcZ$sp(ILoop.scala:878) at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:833) at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:833) at scala.tools.nsc.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:135) at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:833) at scala.tools.nsc.interpreter.ILoop.main(ILoop.scala:900) at xsbt.ConsoleInterface.run(ConsoleInterface.scala:69) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at sbt.compiler.AnalyzingCompiler.call(AnalyzingCompiler.scala:102) at sbt.compiler.AnalyzingCompiler.console(AnalyzingCompiler.scala:77) at sbt.Console.sbt$Console$$console0$1(Console.scala:23) at sbt.Console$$anonfun$apply$2$$anonfun$apply$1.apply$mcV$sp(Console.scala:24) at sbt.Console$$anonfun$apply$2$$anonfun$apply$1.apply(Console.scala:24) at sbt.Console$$anonfun$apply$2$$anonfun$apply$1.apply(Console.scala:24) at sbt.Logger$$anon$4.apply(Logger.scala:90) at sbt.TrapExit$App.run(TrapExit.scala:244) at java.lang.Thread.run(Thread.java:722) {code}

    JIRA | 3 years ago | Brandon Hudgeons
    java.lang.ClassCastException: scala.collection.immutable.$colon$colon cannot be cast to com.mongodb.casbah.commons.MongoDBList
  2. 0

    {code} scala> val test = testcollections.testcoll test: com.mongodb.casbah.MongoCollection = testtest scala> import com.mongodb.casbah.Imports._ import com.mongodb.casbah.Imports._ scala> test.save(MongoDBObject("list" -> List("one", "two", "three"))) // save a list to mongodb res1: com.mongodb.WriteResult = N/A scala> val o = test.findOne.get // get back the thing we just saved o: test.T = { "_id" : { "$oid" : "52f559c63004ae5f4863ef4e"} , "list" : [ "one" , "two" , "three"]} scala> o.getAs[MongoDBList]("list") // get the list out res2: Option[com.mongodb.casbah.Imports.MongoDBList] = Some([ "one" , "two" , "three"]) scala> o.getAs[MongoDBList]("list").get.toList // turn it from Option[MongoDBList] to a scala List[Any] res3: List[Any] = List(one, two, three) scala> o.getAs[MongoDBList]("list").map(_.toList) // same thing, but use map so we get an Option[List[Any]] res8: Option[List[Any]] = Some(List(one, two, three)) scala> o += "list" -> List("one", "two", "three") // set the "list" again, the same way we did before res4: com.mongodb.casbah.commons.MongoDBObject = { "_id" : { "$oid" : "52f559c63004ae5f4863ef4e"} , "list" : [ "one" , "two" , "three"]} scala> o.getAs[MongoDBList]("list") // get the list out again res5: Option[com.mongodb.casbah.Imports.MongoDBList] = Some(List(one, two, three)) scala> o.getAs[MongoDBList]("list").get.toList // same thing we did before ... works fine. res6: List[Any] = List(one, two, three) scala> o.getAs[MongoDBList]("list").map(_.toList) // same thing we did before ... DOH! java.lang.ClassCastException: scala.collection.immutable.$colon$colon cannot be cast to com.mongodb.casbah.commons.MongoDBList at $anonfun$1.apply(<console>:15) at scala.Option.map(Option.scala:145) at .<init>(<console>:15) at .<clinit>(<console>) at .<init>(<console>:7) at .<clinit>(<console>) at $print(<console>) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:734) at scala.tools.nsc.interpreter.IMain$Request.loadAndRun(IMain.scala:983) at scala.tools.nsc.interpreter.IMain.loadAndRunReq$1(IMain.scala:573) at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:604) at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:568) at scala.tools.nsc.interpreter.ILoop.reallyInterpret$1(ILoop.scala:756) at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:801) at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:713) at scala.tools.nsc.interpreter.ILoop.processLine$1(ILoop.scala:577) at scala.tools.nsc.interpreter.ILoop.innerLoop$1(ILoop.scala:584) at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:587) at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply$mcZ$sp(ILoop.scala:878) at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:833) at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:833) at scala.tools.nsc.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:135) at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:833) at scala.tools.nsc.interpreter.ILoop.main(ILoop.scala:900) at xsbt.ConsoleInterface.run(ConsoleInterface.scala:69) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at sbt.compiler.AnalyzingCompiler.call(AnalyzingCompiler.scala:102) at sbt.compiler.AnalyzingCompiler.console(AnalyzingCompiler.scala:77) at sbt.Console.sbt$Console$$console0$1(Console.scala:23) at sbt.Console$$anonfun$apply$2$$anonfun$apply$1.apply$mcV$sp(Console.scala:24) at sbt.Console$$anonfun$apply$2$$anonfun$apply$1.apply(Console.scala:24) at sbt.Console$$anonfun$apply$2$$anonfun$apply$1.apply(Console.scala:24) at sbt.Logger$$anon$4.apply(Logger.scala:90) at sbt.TrapExit$App.run(TrapExit.scala:244) at java.lang.Thread.run(Thread.java:722) {code}

    JIRA | 3 years ago | Brandon Hudgeons
    java.lang.ClassCastException: scala.collection.immutable.$colon$colon cannot be cast to com.mongodb.casbah.commons.MongoDBList
  3. 0

    ClassCastException with subGraph

    GitHub | 1 year ago | parkan
    java.lang.ClassCastException: org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph cannot be cast to org.apache.tinkerpop.gremlin.structure.Edge
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    BasicDBList cannot be cast to scala.collection.immutable.List

    GitHub | 6 years ago | timperrett
    java.lang.ClassCastException: com.mongodb.BasicDBList cannot be cast to scala.collection.immutable.List
  6. 0

    GitHub comment 209#150727154

    GitHub | 1 year ago | jarreds
    java.lang.ClassCastException: java.lang.String cannot be cast to FooAnyVal

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.ClassCastException

      scala.collection.immutable.$colon$colon cannot be cast to com.mongodb.casbah.commons.MongoDBList

      at $anonfun$1.apply()
    2. Unknown
      $anonfun$1.apply
      1. $anonfun$1.apply(<console>:15)
      1 frame
    3. Scala
      Option.map
      1. scala.Option.map(Option.scala:145)
      1 frame