Skip to content
Browse files

fixes a crash in ReflectionUtils.systemProperties

Due to SI-7465 we were erroneously assuming that System.getProperties
only contains string key and string values. This led to a CCE when there
was something else.
  • Loading branch information...
1 parent 5c77e01 commit a3d03ab8667e09e53c74d3fbb0cd7b8ae00fc8c9 @xeno-by xeno-by committed May 9, 2013
View
6 src/reflect/scala/reflect/runtime/ReflectionUtils.scala
@@ -28,9 +28,11 @@ private[scala] object ReflectionUtils {
case ex if pf isDefinedAt unwrapThrowable(ex) => pf(unwrapThrowable(ex))
}
- private def systemProperties: Iterator[(String, String)] = {
+ private def systemProperties: Map[String, String] = {
import scala.collection.JavaConverters._
- System.getProperties.asScala.iterator
+ // cannot use System.getProperties.asScala because of SI-7465
+ val javaProperties: java.util.Dictionary[Object, Object] = System.getProperties
+ javaProperties.asScala.collect{ case (k: String, v: String) => (k, v) }.toMap
}
private def inferBootClasspath: String = (
View
26 test/files/run/macro-system-properties.check
@@ -0,0 +1,26 @@
+Type in expressions to have them evaluated.
+Type :help for more information.
+
+scala>
+
+scala> import language.experimental._, reflect.macros.Context
+import language.experimental._
+import reflect.macros.Context
+
+scala> object GrabContext {
+ def lastContext = Option(System.getProperties.get("lastContext").asInstanceOf[reflect.macros.runtime.Context])
+ // System.properties lets you stash true globals (unlike statics which are classloader scoped)
+ def impl(c: Context)() = { System.getProperties.put("lastContext", c); c.literalUnit }
+ def grab() = macro impl
+ }
+defined module GrabContext
+
+scala> object Test { class C(implicit a: Any) { GrabContext.grab } }
+defined module Test
+
+scala> object Test { class C(implicit a: Any) { GrabContext.grab } }
+defined module Test
+
+scala>
+
+scala>
View
16 test/files/run/macro-system-properties.scala
@@ -0,0 +1,16 @@
+import scala.tools.nsc._
+import scala.tools.partest.ReplTest
+
+object Test extends ReplTest {
+ def code = """
+ import language.experimental._, reflect.macros.Context
+ object GrabContext {
+ def lastContext = Option(System.getProperties.get("lastContext").asInstanceOf[reflect.macros.runtime.Context])
+ // System.properties lets you stash true globals (unlike statics which are classloader scoped)
+ def impl(c: Context)() = { System.getProperties.put("lastContext", c); c.literalUnit }
+ def grab() = macro impl
+ }
+ object Test { class C(implicit a: Any) { GrabContext.grab } }
+ object Test { class C(implicit a: Any) { GrabContext.grab } }
+ """
+}

0 comments on commit a3d03ab

Please sign in to comment.
Something went wrong with that request. Please try again.