1
votes

I am migrating my app from Play! 2.1 to 2.3.

Compilation errors are gone and having few failing tests.

One of them is Anorm related.

[error]    NullPointerException:   (BatchSql.scala:100)
[error] anorm.BatchSql$class.execute(BatchSql.scala:100)
[error] anorm.BatchSql$Copy.execute(BatchSql.scala:193)
[error] models.StoreUser$.insertByCsv(User.scala:314)

Sounds like I need to hack Anorm code. I consult the following page to compile Play! from source:

https://www.playframework.com/documentation/2.3.x/BuildingFromSource

$ git clone git://github.com/playframework/playframework.git
$ cd playframework
$ git checkout remotes/origin/2.3.x

As a start point, I tried to change playframework/framework/src/anorm/src/main/scala/anorm/BatchSql.scala

  def execute()(implicit connection: Connection): Array[Int] = {
    val s = getFilledStatement(connection)
    println("*** statement = " + s)
Thread.sleep(30000)
    s.executeBatch()
  }

Compile and publish locally:

$ PLAY_OPTS=-Dscala.version=2.11.6 ./build clean publish-local

Remove my ivy cache:

$ rm -rf ~/.ivy2/cache

Change my project's project/plugins.sbt:

//addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.3.8")
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.3-SNAPSHOT")

Build.sbt file:

libraryDependencies ++= Seq(
  "postgresql" % "postgresql" % "9.1-901.jdbc4",
  "com.typesafe.play" %% "play-mailer" % "2.4.0",
...
  jdbc,
//  anorm,
  "com.typesafe.play" %% "anorm" % "2.3-SNAPSHOT",
  cache,
  ws,
  filters
)

Reload my project and test-only my failing test again.

But no print message ('*** statement = xxx'") is shown.

How can I use my modified Anorm code?

Update:

I git cloned anorm only from https://github.com/playframework/anorm and invoked publish-local. In this way, now I can use my own compiled anorm in Play!. The root cause is that recent version of anorm requires at least one list of paramters when invoking batch query (https://github.com/playframework/anorm/blob/master/docs/manual/working/scalaGuide/main/sql/ScalaAnorm.md).

Batch update must be called with at least one list of parameter. If a batch is executed with the mandatory first list of parameter being empty (e.g. Nil), only one statement will be executed (without parameter), which is equivalent to SQL(statement).executeUpdate().

If no parameters are served, NPE will be thrown. I fixed my application not to invoke execute() method if the parameter list is empty.

1
First which version raises the exception, and in which case. Then I would add that 2.3-SNAPSHOT is not the version of master/next release, which will is 2.4-SNAPSHOT. If you try to build Anorm, the new repo is github.com/playframework/anorm , and so I would suggest to update your dependency as "com.typesafe.play" %% "anorm" % "2.4-SNAPSHOT" changing().cchantep
Thanks for your comment. I confirmed this exception in Play! 2.3.6. Well, I do not want to try the latest version of anorm but just want to try changing the anorm code and how it goes to determine the root cause of the exception. So my question is how to use my changed anorm with Play!.ruimo
playframework.com/documentation/2.3.x/BuildingFromSource . I confirm the exception for anorm 2.3.6, so you can first try to update dependency to 2.3.8 .cchantep
Thanks, I found the root cause of this problem. I have updated my question.ruimo

1 Answers

0
votes

So it seems your code raise the same misuse as issue #14: batch should never be called without parameter.

The next release will prevent such call.