question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Request.bodyParam() return null and cause stacktrace

See original GitHub issue

Hi ! I cloned your sample tipsy/javalin-kotlin-example to try your technology which I found very interesting !

Explanations

After the repo was cloned, I imported the project on IntelliJ (ultimate edition). I ran the project from the Main.kt class and I tried some of the API routes.

All the routes using the GET method work totally fine but the routes which need to parse the request body trigger a stacktrace in the console and the creation or update is aborted.

Those routes doesn’t work :

  • http://localhost:7000/users/create
  • http://localhost:7000/users/update/:id

After some debugging, I found that the method bodyParam() in the Request class return null.

Here an example of a request which does not work :

  • route: http://localhost:7000/users/create
  • method: POST
  • body: { "name":"Michel", "email":"michel@test.com" }

When I do println(req.body()) at the top of the method, I get this :

{
	"name": "Michel",
	"email": "michel@alice.kt"
}

So, the body is well retrieved in the request !

But when I do println("name="+req.bodyParam("name")+", email="+req.bodyParam("email")), I get :

name=null, email=null

Stacktraces

Here the first stacktrace when we use the alias Request.bp(key: String) setted up at the bottom of the Main.kt file :

java.lang.IllegalStateException: this.bodyParam(key) must not be null
	at app.MainKt.bp(Main.kt:59)
	at app.MainKt$main$$inlined$with$lambda$4.handle(Main.kt:28)
	at io.javalin.core.JavalinServlet.service(JavalinServlet.java:62)
	at io.javalin.embeddedserver.jetty.JettyHandler.doHandle(JettyHandler.java:35)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1568)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
	at org.eclipse.jetty.server.Server.handle(Server.java:564)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:317)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:110)
	at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124)
	at org.eclipse.jetty.util.thread.Invocable.invokePreferred(Invocable.java:128)
	at org.eclipse.jetty.util.thread.Invocable$InvocableExecutor.invoke(Invocable.java:222)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:294)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:199)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:672)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:590)
	at java.lang.Thread.run(Thread.java:745)

Then, this is the stacktrace when we use the bodyParam() method :

java.lang.IllegalStateException: req.bodyParam("name") must not be null
	at app.MainKt$main$$inlined$with$lambda$4.handle(Main.kt:28)
	at io.javalin.core.JavalinServlet.service(JavalinServlet.java:62)
	at io.javalin.embeddedserver.jetty.JettyHandler.doHandle(JettyHandler.java:35)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1568)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
	at org.eclipse.jetty.server.Server.handle(Server.java:564)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:317)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:110)
	at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124)
	at org.eclipse.jetty.util.thread.Invocable.invokePreferred(Invocable.java:128)
	at org.eclipse.jetty.util.thread.Invocable$InvocableExecutor.invoke(Invocable.java:222)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:294)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:199)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:672)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:590)
	at java.lang.Thread.run(Thread.java:745)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
SylvainMartycommented, Jun 3, 2017

Okay nice work ! I’ll try to use Javalin with a database later to compare it with Spring MVC ! Good continuation on the project 😉

0reactions
tipsycommented, Jun 3, 2017

Javalin has an optional dependency on Jackson to do req.bodyAsClass() and res.json(). In this specific example I’m using jackson-kotlin:

<dependency>
    <groupId>com.fasterxml.jackson.module</groupId>
    <artifactId>jackson-module-kotlin</artifactId>
    <version>2.8.4</version>
</dependency>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Request.bodyParam() return null and cause stacktrace #12
After some debugging, I found that the method bodyParam() in the Request class return null. Here an example of a request which does...
Read more >
java - random NullPointerException / onErrorDropped using ...
So it looks like request.getSession() returns null... but I have no idea why, and I am not able to find a pattern. Sometimes...
Read more >
Debugging System.NullReferenceException - elmah.io Blog
The window says "ConsoleApp18.User.Address.get returned null". Exactly what we wanted to see. This will require you to run the code locally, ...
Read more >
Exception::getTraceAsString - Manual - PHP
Returns the Exception stack trace as a string. Parameters ¶. This function has no parameters. Return Values ¶. Returns the Exception stack trace...
Read more >
Value cannot be null.\r\nParameter name: request.Credentials ...
Error received in HTTP response body HTTP Response Body: {"Message":"An error has occurred.","ExceptionMessage":"Value cannot be null.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found