summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2013-12-10 11:17:47 -0800
committerAdriaan Moors <adriaan.moors@typesafe.com>2013-12-10 11:17:47 -0800
commit4aaee3bd20289e617d9fc2d9f41cb6368c7e09d1 (patch)
tree5a9e576cb61606e0785a69dccb5e3a1c67470d28 /src
parent0b77398be2fbfc9270ae8af0ef56964a5eab5537 (diff)
parent006e2f2aadf5d15ff1b9b32f1b7e96960b778933 (diff)
downloadscala-4aaee3bd20289e617d9fc2d9f41cb6368c7e09d1.tar.gz
scala-4aaee3bd20289e617d9fc2d9f41cb6368c7e09d1.tar.bz2
scala-4aaee3bd20289e617d9fc2d9f41cb6368c7e09d1.zip
Merge pull request #3249 from retronym/ticket/7912
SI-7912 Be defensive calling `toString` in `MatchError#getMessage`
Diffstat (limited to 'src')
-rw-r--r--src/library/scala/MatchError.scala10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/library/scala/MatchError.scala b/src/library/scala/MatchError.scala
index 6ba7e833d3..9965bb19b5 100644
--- a/src/library/scala/MatchError.scala
+++ b/src/library/scala/MatchError.scala
@@ -23,9 +23,15 @@ final class MatchError(obj: Any) extends RuntimeException {
/** There's no reason we need to call toString eagerly,
* so defer it until getMessage is called.
*/
- private lazy val objString =
+ private lazy val objString = {
+ def ofClass = "of class " + obj.getClass.getName
if (obj == null) "null"
- else obj.toString() + " (of class " + obj.getClass.getName + ")"
+ else try {
+ obj.toString() + " (" + ofClass + ")"
+ } catch {
+ case _: Throwable => "an instance " + ofClass
+ }
+ }
override def getMessage() = objString
}