Our app is Scala-based and built on the Play! framework. I’ve generated a random number using Scala Random. This is to use as a unique key for each account in our app.
However, when I go to save the new account into the database, it throws a java.lang.NumberFormatException:
More Info: I’m converting a string of an account ID to a Scala Long. I’m looking it up using a Squeryl object, grabbing the ID, and then converting it. Here’s what it looks like:
val account_id = Account.findAccountByUnique(account.uniqueKey).id.toLong
This is what findAccountByUnique looks like:
def findAccountByUnique(criteria: String) = {
from(DB.accounts)(a =>
where(a.uniqueKey == criteria)
select (a))
}
The stack trace on error:
java.lang.NumberFormatException: For input string: "468b68c"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Long.parseLong(Unknown Source)
at java.lang.Long.parseLong(Unknown Source)
at scala.collection.immutable.StringLike$class.toLong(StringLike.scala:209)
at scala.collection.immutable.StringOps.toLong(StringOps.scala:31)
at controllers.Accounts$.save(Accounts.scala:44)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:548)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:502)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:496)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:473)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:161)
at play.server.PlayHandler$NettyInvocation.execute(PlayHandler.java:257)
at play.Invoker$Invocation.run(Invoker.java:278)
at play.server.PlayHandler$NettyInvocation.run(PlayHandler.java:235)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
I’ve typecasted the unique key as both a Scala Long and String but it throws the same error. Any idea as to a fix?
After further investigation it looks like there was a database helper returning junk data. Essentially it was actually returning its own “sample” data which happened to be a hexadecimal. It was a lib in Squeryl, looks like something was malformed somewhere and therefore it triggered a “sample” response.
Looks like because
account.uniqueKeyhad been updated from a previous query, it brought some junk with it. Still investigating how it happened but at least I found the real problem.