MindscapeHQ / raygun4java

Java SDK for the Raygun service
https://raygun.com
MIT License
23 stars 21 forks source link

RaygunServletMessageBuilder throws NPE when no user has been set #12

Closed ghost closed 10 years ago

ghost commented 10 years ago

When RaygunServletMessageBuilder#SetUser has never been called, the #Build() method throws a NullPointerException when trying to load the user from the nested message's details:

java.lang.NullPointerException
        at com.mindscapehq.raygun4java.core.messages.RaygunMessageDetails.getUser(RaygunMessageDetails.java:61)
        at com.mindscapehq.raygun4java.webprovider.RaygunServletMessageBuilder.Build(RaygunServletMessageBuilder.java:30)
        at com.mindscapehq.raygun4java.webprovider.RaygunServletMessageBuilder.Build(RaygunServletMessageBuilder.java:7)

If the SetUser checks for the user being null, the GetUser should do so as well!

fundead commented 10 years ago

Thanks for reporting this issue and the stack trace. Interestingly I've looked into it and cannot reproduce the behaviour you're seeing; the unit tests pass and the ServletClient work in a Glassfish instance without throwing an NPE on the affected lines, with RG4Java 1.3.1

Can you please comment with your environment details (JDK ver, server, Raygun4Java version) and if possible a minimal repro project that exhibits the behaviour.

Regards,

Callum Gavin Mindscape Limited

ghost commented 10 years ago

Sorry, I should have given more details.

I'm using the RaygunServletMessageBuilder manually, because I want to share code for handling both RaygunServletMessage and RaygunMessage. When using the RaygunServletClient, it calls SetUser with null, if no user was set in the client.

When SetUser is not called at all, (not even with null), the above error occurs. I don't think GetUser should cause an error when SetUser has not been called, it should simply return null.

fundead commented 10 years ago

Ah I understand your use case - and indeed you are correct that it should return null. I've implemented and tested the fix and it appears to be working well on my end now.

If you're grabbing the source via Git the new 1.3.2 version on the master branch contains the fix, and there's a Maven release in the pipeline if it works correct for you too. This is a fix for the core module (specifically core/messages/RaygunMessageDetails.java), but it lets the RgServletMessageBuilder set a null user as expected.

Hope this improves your Raygun experience - if there's any more issues let us know.