Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE because message is null. #6

Closed
smccants opened this issue Jan 15, 2015 · 3 comments
Closed

NPE because message is null. #6

smccants opened this issue Jan 15, 2015 · 3 comments

Comments

@smccants
Copy link

I ran into the following NullPointerException:

16:40:01,170 |-ERROR in com.eclecticlogic.whisper.logback.WhisperAppender[whisper] - Appender [whisper] failed to append. java.lang.NullPointerException
at java.lang.NullPointerException
at at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:768)
at at com.eclecticlogic.whisper.core.WhisperManager.log(WhisperManager.java:82)
at at com.eclecticlogic.whisper.logback.WhisperAppender.append(WhisperAppender.java:90)
at at com.eclecticlogic.whisper.logback.WhisperAppender.append(WhisperAppender.java:37)

I back tracked that to the original error message (logged by the File Appender):

14-01 16:40:01 [ajp-bio-8812-exec-12] com.hcs.data.dao.jdbc.util.JDBCDAOUtil ERROR null
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'webtl_orc_dev_1_4_3.procedures' doesn't exist

Which came from this code in my application:

   } catch (SQLException ex) {
        log.log(Level.SEVERE, null, ex);
    }

While you can make a good argument that it is poor form to provide a null message, it does not cause problems for Logback's File Appender or SMTP Appender. Even if the WhisperAppender didn't throw an NPE, it would cause problems for the digest if I have multiple different "errors" being logged with a null message.

So, my question/bug/concern is two fold:

  1. Is there a better way to handle this then throwing an NPE when the message is null?
  2. Is there a better way to recognize duplicate messages that have null messages?

I can fix my code, of course, but it is easy enough for another null message to creep back in at a later date (old programming habits can die hard), which could cause us to miss important error messages.

This may or may not be a bug, but I couldn't find anywhere else to raise the question, so my apologies if this was the wrong spot.

@smccants
Copy link
Author

Did a quick search of my code and came up with 172 instances of log(Level.SEVERE, null,. Yikes!

@eclecticlogic
Copy link
Collaborator

Logging null is an application error but Whisper should handle it. For now I've modified the code to treat null as a string "null" for the log message. Please upgrade to 1.0.4. I just pushed 1.0.4 out so Maven Central's index may not have it. But if you simply change the version string in your pom, maven/gradle etc. should pull it.

@smccants
Copy link
Author

Thanks for the prompt response and fix! Version 1.0.4 is working for me now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant