Skip to content

Commit af4a529

Browse files
committed
Fix for PartialFunction NPE.
Was going straight to the field and bypassing the null guard. Closes SI-5300.
1 parent 1684bae commit af4a529

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/library/scala/runtime/AbstractPartialFunction.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ abstract class AbstractPartialFunction[-T1, +R]
2626
private var fallBackField: PartialFunction[T1 @uncheckedVariance, R @uncheckedVariance] = _
2727

2828
def fallBack: PartialFunction[T1, R] = synchronized {
29-
if (fallBackField == null) fallBackField = PartialFunction.empty
29+
if (fallBackField eq null) fallBackField = PartialFunction.empty
3030
fallBackField
3131
}
3232

@@ -38,7 +38,7 @@ abstract class AbstractPartialFunction[-T1, +R]
3838
override def orElse[A1 <: T1, B1 >: R](that: PartialFunction[A1, B1]) : PartialFunction[A1, B1] = {
3939
val result = this.clone.asInstanceOf[AbstractPartialFunction[A1, B1]]
4040
result.synchronized {
41-
result.fallBackField = this.fallBackField orElse that
41+
result.fallBackField = if (this.fallBackField eq null) that else this.fallBackField orElse that
4242
result
4343
}
4444
}

test/files/run/t5300.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object Test {
2+
val pf: PartialFunction[Any, Unit] = { case _ => () }
3+
4+
def main(args: Array[String]): Unit = {
5+
pf orElse pf
6+
}
7+
}

0 commit comments

Comments
 (0)