Skip to content

Instantly share code, notes, and snippets.

@teamon
Created July 26, 2011 17:22
Show Gist options
  • Save teamon/1af85bff5de659b3d266 to your computer and use it in GitHub Desktop.
Save teamon/1af85bff5de659b3d266 to your computer and use it in GitHub Desktop.
scala> util.Properties.versionMsg
res0: String = Scala library version 2.9.0.final -- Copyright 2002-2011, LAMP/EPFL
scala> :load /Users/teamon/Desktop/test.scala
Loading /Users/teamon/Desktop/test.scala...
import java.io._
defined module Levels
defined class Entries
encode: (msg: Any)Array[Byte]
decode: (bytes: Array[Byte])Any
test: (a: Any)Unit
Entries(Map(a -> Trace))
[B@1235047f
Entries(Map(a -> Trace))
Entries(Map(a -> Trace, b -> Trace))
[B@507895d8
Entries(Map(a -> Trace, b -> Trace))
Entries(Map(e -> Trace, a -> Trace, b -> Debug, c -> Trace, d -> Trace))
[B@77b993d6
Entries(Map(e -> Trace, a -> Trace, b -> Debug, c -> Trace, d -> Trace))
scala>
scala> util.Properties.versionMsg
res0: String = Scala library version 2.9.0.final -- Copyright 2002-2011, LAMP/EPFL
scala> :load /Users/teamon/Desktop/test.scala
Loading /Users/teamon/Desktop/test.scala...
import java.io._
defined module Levels
defined class Entries
encode: (msg: Any)Array[Byte]
decode: (bytes: Array[Byte])Any
test: (a: Any)Unit
Entries(Map(a -> Trace))
[B@56f4defc
Entries(Map(a -> Trace))
Entries(Map(a -> Trace, b -> Trace))
[B@60051f44
Entries(Map(a -> Trace, b -> Trace))
Entries(Map(e -> Trace, a -> Trace, b -> Debug, c -> Trace, d -> Trace))
[B@5f297ee0
java.lang.ClassCastException: cannot assign instance of scala.collection.immutable.HashMap$SerializationProxy to field Entries.entries of type scala.collection.immutable.Map in instance of Entries
at java.io.ObjectStreamClass$FieldReflector.setObjFieldValues(ObjectStreamClass.java:2039)
at java.io.ObjectStreamClass.setObjFieldValues(ObjectStreamClass.java:1212)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1952)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1870)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
at .decode(<console>:12)
at .test(<console>:15)
at .<init>(<console>:17)
at .<clinit>(<console>)
at .<init>(<console>:11)
at .<clinit>(<console>)
at $export(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:592)
at scala.tools.nsc.interpreter.IMain$Request$$anonfun$10.apply(IMain.scala:828)
at scala.tools.nsc.interpreter.Line$$anonfun$1.apply$mcV$sp(Line.scala:43)
at scala.tools.nsc.io.package$$anon$2.run(package.scala:31)
at java.lang.Thread.run(Thread.java:680)
scala>
import java.io._
object Levels extends Enumeration {
val Trace, Debug, Info, Warn, Error = Value
}
case class Entries(entries: Map[String, Levels.Value])
// object Test {
// def main(args: Array[String]): Unit = {
def encode(msg: Any) = {
val bos = new ByteArrayOutputStream
val out = new ObjectOutputStream(bos)
out.writeObject(msg)
out.close
bos.toByteArray()
}
def decode(bytes: Array[Byte]) = {
val in = new ObjectInputStream(new ByteArrayInputStream(bytes))
val obj: Any = in.readObject
in.close
obj
}
def test(a: Any){
println(a)
println(encode(a))
println(decode(encode(a)))
println
}
test(Entries(Map("a" -> Levels.Trace)))
test(Entries(Map("a" -> Levels.Trace, "b" -> Levels.Trace)))
test(Entries(Map("a" -> Levels.Trace, "b" -> Levels.Debug, "c" -> Levels.Trace,
"d" -> Levels.Trace, "e" -> Levels.Trace)))
// }
// }
@teamon
Copy link
Author

teamon commented Jul 27, 2011

Tested in both sbt 0.7.7 and 0.10.1, and scala 2.9.0 & 2.9.0-1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment