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.

JsonMappingException causes NullPointerException

See original GitHub issue

Mapping errors that result in a JsonMappingException produce NullPointerException. This is caused by the fact that the client tries to get the error stream from the connection if an IOException is thrown. But JsonMappingException also extends IOException. This means the client will try to get the error stream on JsonMappingException and this causes the NPE because the stream is null:

Caused by: java.lang.NullPointerException: null
    at com.googlecode.jsonrpc4j.NoCloseInputStream.markSupported(NoCloseInputStream.java:85) ~[jsonrpc4j-1.4.3.jar:1.4.3]
    at com.googlecode.jsonrpc4j.ReadContext.assertReadable(ReadContext.java:29) ~[jsonrpc4j-1.4.3.jar:1.4.3]
    at com.googlecode.jsonrpc4j.JsonRpcClient.readResponseNode(JsonRpcClient.java:287) ~[jsonrpc4j-1.4.3.jar:1.4.3]
    at com.googlecode.jsonrpc4j.JsonRpcClient.getValidResponse(JsonRpcClient.java:223) ~[jsonrpc4j-1.4.3.jar:1.4.3]
    at com.googlecode.jsonrpc4j.JsonRpcClient.readResponse(JsonRpcClient.java:173) ~[jsonrpc4j-1.4.3.jar:1.4.3]
    at com.googlecode.jsonrpc4j.JsonRpcClient.readResponse(JsonRpcClient.java:500) ~[jsonrpc4j-1.4.3.jar:1.4.3]
    at com.googlecode.jsonrpc4j.JsonRpcHttpClient.invoke(JsonRpcHttpClient.java:114) ~[jsonrpc4j-1.4.3.jar:1.4.3]
    at com.googlecode.jsonrpc4j.JsonRpcHttpClient.invoke(JsonRpcHttpClient.java:92) ~[jsonrpc4j-1.4.3.jar:1.4.3]

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:4
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
selene-lcommented, Apr 24, 2016

Yep. Same problem. If the method returns an plain string - it’s OK. But if the method returns an object - the library throws NullPointerException. For example:

{
    "jsonrpc":"2.0",
    "id":"113195884",
    "result":{
        "code":0,
        "message":null,
        "output":{
            "userId":"23f975d1-00af-4ae9-aaca-16863b30e1d0",
            "sessionToken":"cd6405b8-2d4b-4249-8c78-0a647c6cf2a4"
        }
    }
}

The stack trace is identical to the listed above. It seems that somewhere missed checking to null.

0reactions
dzolocommented, Jun 8, 2018

I have got a similar problem. When I send an invalid arguments to a method or do anything else that causes JsonMappingException to be thrown then I will get a NullPointerException on client. The reason is that JsonBasicServer handles all exceptions in invoke method (line 375) to a JSON error but these Jackson exceptions do not have a public constructor. But even if they had one this is invalid behavior.

The fix should be done by rethrowing of IOException that will cause that a proper JsonError.PARSE_ERROR error will be created as response in the handleRequest method.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JsonMappingException (was java.lang.NullPointerException)
My theory is that Jackson JSON tries to access it as a primitive datatype, causing the crash. Still not sure what to do...
Read more >
Free plan is causing JsonMappingException and ...
Hello. We are trying to implement KillBill features in our Click2CallMe app, and so far I have managed to generate catalog XML file...
Read more >
Jackson Exceptions - Problems and Solutions - Baeldung
In this tutorial, we'll go over the most common Jackson Exceptions — JsonMappingException and UnrecognizedPropertyException.
Read more >
Error when faceting with "missing":true - Datastax Community
Thread.run(Thread.java:748); Caused by: com.fasterxml.jackson.databind.JsonMappingException: [no message for java.lang.NullPointerException] ...
Read more >
NullPointerException in InvestigationWrapper : TW-78756
JsonMappingException : (was java.lang.NullPointerException) ... ProblemOccurrencesTree$Leaf["problemOccurrences"]), caused by: java.lang.
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