1

I am getting the below error from a simple line of code having log.info statement

java.lang.NullPonterException
    at java.io.Writer.write(Writer.java:157)
    at org.apache.log4j.helpers.CountingQuietWriter.write(CountingQuietWriter.java:45)
    at org.apache.log4j.WritingAppender.subAppend(WriterAppender.java:310)
    at org.apache.log4j.RollingAppender.subAppend(RollingAppender.java:276)
    at org.apache.log4j.WritingAppender.append(WriterAppender.java:162)
    at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:251)
    at org.apache.log4j.helpers.AppenderAttachbleImpl.appendLoopOnAppenders(AppenderAttachbleImpl.java:66)
    at org.apache.log4j.Category.callAppenders(Category.java:206)
    at org.apache.log4j.Category.forcedLog(Category.java:391)
    at org.apache.log4j.Category.info(Category.java:666)
    at com.bizcase.Helper.showTip(Helper.java:32)

Can anyone advice if this issue is encountered?

I am using log4j version 1.2.17 and normal rolling appender .

Its not a NullPonterException for null object.Its coming from log4j library and beyond my control to figure out which log4j property or code is causing this issue.

soumitra chatterjee
  • 2,268
  • 9
  • 26
  • 48
  • Install sources of log4j in your IDE and debug it. In exception row you will see reason of exception. – Ashot Karakhanyan Aug 03 '18 at 22:00
  • *"... beyond my control to figure out which log4j property or code is causing this issue."* - Advice: adjust that attitude. It is not beyond the control of someone who 1) has access to the source code, and 2) has access to a debugger. – Stephen C Aug 03 '18 at 23:12
  • Note - see my answer, which proves that it not "beyond your control" to solve this. (If I can get that far from just the stacktrace, *some* of the source code, and some simple logical deductions, then so could any programmer.) It might be beyond your (current) skill level, but improving your skills >>is<< within your control. – Stephen C Aug 03 '18 at 23:37
  • I don't think this is a dupe, as it's a specific NPE, as your answer shows. Cheers! – rogerdpack Nov 02 '18 at 16:20

1 Answers1

1

Looking at the source code1:

  • "org.apache.log4j.helpers.CountingQuietWriter.write(CountingQuietWriter.java:45)" is a call to Writer.write(String).

  • Writer.write(String) can only throw an NPE if the string is null.

  • That means CountingQuietWriter.write was called with a null argument.

And so on. (You can do the rest!)

I think you will find that the root cause is that org.apache.log4j.Category.info(...) is being called with a null message.

Also, note that the javadoc for Category states:

There is absolutely no need for new client code to use or refer to the Category class. Whenever possible, please avoid referring to it or using it.


So, if com.bizcase.Helper is your code, then it needs to be revised, both to fix the NPE bug and to avoid direct usage of Category.

If it is not your code, you need to figure out where the null string comes from in the info call. My guess would be is that it is a missing tool tip ... or something like that.


1 - I am hampered in this because I don't know the precise versions of Java and log4j that you are using, and therefore can't be sure I have the right source code. And I don't know what the source of com.bizcase.Helper looks like. On the other hand, you ... as the developer ... can find these things out. Which makes it a whole lot easier for you.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216