Here, it's better to avoid casting. Try:

val offset = Option(request.getParameter("offset")).map(_.toLong).getOrElse(0L)