Skip to content

Commit

Permalink
Intentionally cripple Box's .get method for Lift 3.
Browse files Browse the repository at this point in the history
Box.get now returns Nothing, which should break anyone
attempting to use its return type for anything, including tests.

Also fix a Box test that relied on .get.
  • Loading branch information
Shadowfiend committed Apr 7, 2014
1 parent 748f23d commit 50d23b4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
15 changes: 6 additions & 9 deletions core/common/src/main/scala/net/liftweb/common/Box.scala
Expand Up @@ -255,15 +255,12 @@ sealed abstract class Box[+A] extends Product with Serializable{
final def open_! : A = openOrThrowException("Legacy method implementation")
*/
/**
* Return the value contained in this Box if it is Full; throw an
* exception otherwise. Please use openOrThrowException instead. In
* the past, this method triggered an implicit conversion to Option
* and could throw an unintended NullPointerException. That is no longer
* the case, and in Lift 3 this method will be changed to return
* a useless type so that the compiler will break attempts to use it.
*/
@deprecated("use map/flatMap/foreach if possible, or openOrThrowException if you must", "2.6")
final def get: A = open_!
* Exists to avoid the implicit conversion from Box to Option. Opening a Box
* unsafely should be done using openOrThrowException.
*/
final def get: Nothing = {
throw new Exception("Attempted to open a Box incorrectly. Please use openOrThrowException.")
}

/**
* Return the value contained in this Box if it is Full;
Expand Down
7 changes: 1 addition & 6 deletions core/common/src/test/scala/net/liftweb/common/BoxSpec.scala
Expand Up @@ -79,11 +79,6 @@ class BoxSpec extends Specification with ScalaCheck with BoxGenerator {
"be defined from some legacy code (possibly passing null values). If the passed value is null, an Empty is returned" in {
Box.legacyNullTest(null) must_== Empty
}

"have get defined in a way compatible with Option" in {
Full(1).get must_== 1
(Empty: Box[Int]).get must throwA[NullPointerException]
}
}

"A Box" should {
Expand Down Expand Up @@ -299,7 +294,7 @@ class BoxSpec extends Specification with ScalaCheck with BoxGenerator {
"A Failure is an Empty Box which" can {
"return its cause as an exception" in {
case class LiftException(m: String) extends Exception
Failure("error", Full(new LiftException("broken")), Empty).exception.get must_== new LiftException("broken")
Failure("error", Full(new LiftException("broken")), Empty).exception must_== Full(new LiftException("broken"))
}
"return a chained list of causes" in {
Failure("error",
Expand Down

0 comments on commit 50d23b4

Please sign in to comment.