diff options
author | Paul Phillips <paulp@improving.org> | 2012-01-08 19:36:33 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-01-08 19:57:49 -0800 |
commit | af4a5299290090ff433f2ad7bb801bf4226f423f (patch) | |
tree | cff3ece068ac1eb90e29976ebc9d28cdb603473a | |
parent | 1684baefd23a806dbbec7e8f536ac3d624702886 (diff) | |
download | scala-af4a5299290090ff433f2ad7bb801bf4226f423f.tar.gz scala-af4a5299290090ff433f2ad7bb801bf4226f423f.tar.bz2 scala-af4a5299290090ff433f2ad7bb801bf4226f423f.zip |
Fix for PartialFunction NPE.
Was going straight to the field and bypassing the null guard.
Closes SI-5300.
-rw-r--r-- | src/library/scala/runtime/AbstractPartialFunction.scala | 4 | ||||
-rw-r--r-- | test/files/run/t5300.scala | 7 |
2 files changed, 9 insertions, 2 deletions
diff --git a/src/library/scala/runtime/AbstractPartialFunction.scala b/src/library/scala/runtime/AbstractPartialFunction.scala index f48d99f5af..cbe778f09b 100644 --- a/src/library/scala/runtime/AbstractPartialFunction.scala +++ b/src/library/scala/runtime/AbstractPartialFunction.scala @@ -26,7 +26,7 @@ abstract class AbstractPartialFunction[-T1, +R] private var fallBackField: PartialFunction[T1 @uncheckedVariance, R @uncheckedVariance] = _ def fallBack: PartialFunction[T1, R] = synchronized { - if (fallBackField == null) fallBackField = PartialFunction.empty + if (fallBackField eq null) fallBackField = PartialFunction.empty fallBackField } @@ -38,7 +38,7 @@ abstract class AbstractPartialFunction[-T1, +R] override def orElse[A1 <: T1, B1 >: R](that: PartialFunction[A1, B1]) : PartialFunction[A1, B1] = { val result = this.clone.asInstanceOf[AbstractPartialFunction[A1, B1]] result.synchronized { - result.fallBackField = this.fallBackField orElse that + result.fallBackField = if (this.fallBackField eq null) that else this.fallBackField orElse that result } } diff --git a/test/files/run/t5300.scala b/test/files/run/t5300.scala new file mode 100644 index 0000000000..073b29604a --- /dev/null +++ b/test/files/run/t5300.scala @@ -0,0 +1,7 @@ +object Test { + val pf: PartialFunction[Any, Unit] = { case _ => () } + + def main(args: Array[String]): Unit = { + pf orElse pf + } +} |