The code below checks for basic authentication. Here resp is the unauthorized response 401. I check if the Authorization header is present, and if it is present, I check its value, otherwise I call resp :
def validate(authHeader: String): Boolean = { //........ } val authHeader = Option(request.getHeader("Authorization")) authHeader match { case Some(header) if header.startsWith("Basic ") => validate(header) match { case false => resp } case _ => resp }
When I compile it, it gives an error for the match { case false => resp } saying found: scala.Boolean(false) required: java.lang.Boolean . I am confused about why its handling of scala Boolean is different from java Boolean.
I noticed that at the beginning of the file was the line import java.lang._ (I do not know why). I commented on this, and in the code, instead of a warning, a warning is issued:
warning: match may not be exhaustive. It would fail on the following input: true
I think this is because I did not write case true . But what made the initial error, and why does this only happen with import java.lang._ ?
EDIT:
Here is a minimal example of a problem:
val f: java.lang.Boolean = false val f2: scala.Boolean = false f match { case false => 5 } f2 match { case false => 5 }
scala boolean
lovesh
source share