[sbt-assembly et al] Got NullPointer Exception when hitting a route on a running play app

I packaged the application using “sbt assembly” then run using “java -jar jarname”.

Then, I got the following error although it was perfectly running fine when running as “sbt run”
Cannot invoke the action, eventually got an error: java.lang.NullPointerException

Note: Play 2.3 is a bit old but once this is sorted, there is a good chance my project/app will start using later/latest version of play.

Play Version

2.3.9

API

Scala 2.10.5

Operating System

MacOS or Linux

JDK

1.8

Library Dependencies

Expected Behavior

Normally running app.

Actual Behavior

I packaged the application using “sbt assembly” then run using “java -jar jarname”.

Then, I got the following error although it was perfectly running fine when running as “sbt run”

Cannot invoke the action, eventually got an error: java.lang.NullPointerException

A bit more stack trace:

2019-10-27 20:55:55,525 - [INFO] - from play in main 
Application started (Prod)

2019-10-27 20:55:55,603 - [INFO] - from play in main 
Listening for HTTP on /0:0:0:0:0:0:0:0:9000

2019-10-27 20:56:03,225 - [INFO] - from akka.event.slf4j.Slf4jLogger in play-akka.actor.default-dispatcher-2 
Slf4jLogger started

2019-10-27 20:56:03,234 - [ERROR] - from play in New I/O worker #1 
Cannot invoke the action, eventually got an error: java.lang.NullPointerException

2019-10-27 20:56:03,240 - [ERROR] - from application in New I/O worker #1 


! @7djbeg7g8 - Internal server error, for (GET) [/] ->

play.api.Application$$anon$1: Execution exception[[NullPointerException: null]]
	at play.api.Application$class.handleError(Application.scala:296) ~[my-app.jar:2.0.1.DEV]
	at play.api.DefaultApplication.handleError(Application.scala:402) [my-app.jar:2.0.1.DEV]
	at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3$$anonfun$applyOrElse$4.apply(PlayDefaultUpstreamHandler.scala:320) [my-app.jar:2.0.1.DEV]
	at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3$$anonfun$applyOrElse$4.apply(PlayDefaultUpstreamHandler.scala:320) [my-app.jar:2.0.1.DEV]
	at scala.Option.map(Option.scala:145) [my-app.jar:2.0.1.DEV]
	at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3.applyOrElse(PlayDefaultUpstreamHandler.scala:320) [my-app.jar:2.0.1.DEV]
	at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3.applyOrElse(PlayDefaultUpstreamHandler.scala:316) [my-app.jar:2.0.1.DEV]
	at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:344) [my-app.jar:2.0.1.DEV]
	at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:343) [my-app.jar:2.0.1.DEV]
	at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32) [my-app.jar:2.0.1.DEV]
	at play.api.libs.iteratee.Execution$trampoline$.execute(Execution.scala:46) [my-app.jar:2.0.1.DEV]
	at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:40) [my-app.jar:2.0.1.DEV]
	at scala.concurrent.impl.Promise$DefaultPromise.scala$concurrent$impl$Promise$DefaultPromise$$dispatchOrAddCallback(Promise.scala:280) [my-app.jar:2.0.1.DEV]
	at scala.concurrent.impl.Promise$DefaultPromise.onComplete(Promise.scala:270) [my-app.jar:2.0.1.DEV]
	at scala.concurrent.Future$class.recoverWith(Future.scala:343) [my-app.jar:2.0.1.DEV]
	at scala.concurrent.impl.Promise$DefaultPromise.recoverWith(Promise.scala:153) [my-app.jar:2.0.1.DEV]
	at play.core.server.netty.PlayDefaultUpstreamHandler.play$core$server$netty$PlayDefaultUpstreamHandler$$handleAction$1(PlayDefaultUpstreamHandler.scala:316) [my-app.jar:2.0.1.DEV]
	at play.core.server.netty.PlayDefaultUpstreamHandler.messageReceived(PlayDefaultUpstreamHandler.scala:209) [my-app.jar:2.0.1.DEV]
	at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70) [my-app.jar:2.0.1.DEV]
	at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564) [my-app.jar:2.0.1.DEV]
	at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791) [my-app.jar:2.0.1.DEV]
	at com.typesafe.netty.http.pipelining.HttpPipeliningHandler.messageReceived(HttpPipeliningHandler.java:62) [my-app.jar:2.0.1.DEV]
	at org.jboss.netty.channel.SimpleChannelHandler.handleUpstream(SimpleChannelHandler.java:88) [my-app.jar:2.0.1.DEV]
	at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564) [my-app.jar:2.0.1.DEV]
	at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791) [my-app.jar:2.0.1.DEV]
	at org.jboss.netty.handler.codec.http.HttpContentDecoder.messageReceived(HttpContentDecoder.java:108) [my-app.jar:2.0.1.DEV]
	at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70) [my-app.jar:2.0.1.DEV]
	at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564) [my-app.jar:2.0.1.DEV]
	at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791) [my-app.jar:2.0.1.DEV]
	at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:296) [my-app.jar:2.0.1.DEV]
	at org.jboss.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:459) [my-app.jar:2.0.1.DEV]
	at org.jboss.netty.handler.codec.replay.ReplayingDecoder.callDecode(ReplayingDecoder.java:536) [my-app.jar:2.0.1.DEV]
	at org.jboss.netty.handler.codec.replay.ReplayingDecoder.messageReceived(ReplayingDecoder.java:435) [my-app.jar:2.0.1.DEV]
	at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70) [my-app.jar:2.0.1.DEV]
	at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564) [my-app.jar:2.0.1.DEV]
	at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559) [my-app.jar:2.0.1.DEV]
	at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268) [my-app.jar:2.0.1.DEV]
	at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255) [my-app.jar:2.0.1.DEV]
	at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:88) [my-app.jar:2.0.1.DEV]
	at org.jboss.netty.channel.socket.nio.AbstractNioWorker.process(AbstractNioWorker.java:108) [my-app.jar:2.0.1.DEV]
	at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:337) [my-app.jar:2.0.1.DEV]
	at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:89) [my-app.jar:2.0.1.DEV]
	at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178) [my-app.jar:2.0.1.DEV]
	at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108) [my-app.jar:2.0.1.DEV]
	at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42) [my-app.jar:2.0.1.DEV]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_131]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_131]
	at java.lang.Thread.run(Thread.java:748) [na:1.8.0_131]
Caused by: java.lang.NullPointerException: null
	at play.api.mvc.FilterChain$$anon$2$$anonfun$2.apply(Filters.scala:106) ~[my-app.jar:2.0.1.DEV]
	at play.api.mvc.FilterChain$$anon$2$$anonfun$2.apply(Filters.scala:106) ~[my-app.jar:2.0.1.DEV]
	at scala.collection.LinearSeqOptimized$class.foldLeft(LinearSeqOptimized.scala:111) ~[my-app.jar:2.0.1.DEV]
	at scala.collection.immutable.List.foldLeft(List.scala:84) ~[my-app.jar:2.0.1.DEV]
	at play.api.mvc.FilterChain$$anon$2.apply(Filters.scala:106) ~[my-app.jar:2.0.1.DEV]
	at play.api.mvc.FilterChain$$anon$2.apply(Filters.scala:104) ~[my-app.jar:2.0.1.DEV]
	at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$14.apply(PlayDefaultUpstreamHandler.scala:202) ~[my-app.jar:2.0.1.DEV]
	at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$14.apply(PlayDefaultUpstreamHandler.scala:200) ~[my-app.jar:2.0.1.DEV]
	at play.api.mvc.EssentialAction$$anon$2.apply(Action.scala:82) ~[my-app.jar:2.0.1.DEV]
	at play.api.mvc.EssentialAction$$anon$2.apply(Action.scala:81) ~[my-app.jar:2.0.1.DEV]
	at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$20.apply(PlayDefaultUpstreamHandler.scala:253) ~[my-app.jar:2.0.1.DEV]
	at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$20.apply(PlayDefaultUpstreamHandler.scala:253) ~[my-app.jar:2.0.1.DEV]
	at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24) ~[my-app.jar:2.0.1.DEV]
	at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) ~[my-app.jar:2.0.1.DEV]
	at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:41) ~[my-app.jar:2.0.1.DEV]
	at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:393) ~[my-app.jar:2.0.1.DEV]
	at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) ~[my-app.jar:2.0.1.DEV]
	at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) ~[my-app.jar:2.0.1.DEV]
	at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) ~[my-app.jar:2.0.1.DEV]
	at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) ~[my-app.jar:2.0.1.DEV]


Reproducible Test Case

NA

Help or any pointer to debug further on this problem would be truly helpful. Thanks