You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by bu...@apache.org on 2005/10/28 02:51:09 UTC

DO NOT REPLY [Bug 35743] - SyslogAppender throws a NullPointerException upon misconfiguration

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=35743>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=35743





------- Additional Comments From jwm@horde.net  2005-10-28 02:51 -------
I noticed the same thing recently. Specifying an unresolvable syslog server
results in a null InetAddress (SyslogWriter.address). SyslogWriter.flush() does
not check that ds.address is not null, so DatagramSocket.send() throws a
NullPointerException.

Sample exception output:

log4j:ERROR Could not find foo. All logging will FAIL.
java.net.UnknownHostException: foo: foo
        at java.net.InetAddress.getAllByName0(InetAddress.java:1011)
        at java.net.InetAddress.getAllByName0(InetAddress.java:981)
        at java.net.InetAddress.getAllByName(InetAddress.java:975) 
        at java.net.InetAddress.getByName(InetAddress.java:889)
        at org.apache.log4j.helpers.SyslogWriter.<init>(SyslogWriter.java:47)
        at
org.apache.log4j.net.SyslogAppender.setSyslogHost(SyslogAppender.java:297)
        at net.horde.pv.PV.main(PV.java:87)

Exception in thread "main" java.lang.NullPointerException: null buffer || null
address
        at java.net.PlainDatagramSocketImpl.send(Native Method)
        at java.net.DatagramSocket.send(DatagramSocket.java:611)
        at org.apache.log4j.helpers.SyslogWriter.write(SyslogWriter.java:77)
        at org.apache.log4j.helpers.QuietWriter.write(QuietWriter.java:47)
        at
org.apache.log4j.helpers.SyslogQuietWriter.write(SyslogQuietWriter.java:53)
        at org.apache.log4j.net.SyslogAppender.append(SyslogAppender.java:254)
        at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:230)
        at
org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:65)
        at org.apache.log4j.Category.callAppenders(Category.java:203)
        at org.apache.log4j.Category.forcedLog(Category.java:388)
        at org.apache.log4j.Category.debug(Category.java:257)
        at net.horde.pv.PV.main(PV.java:114)

The following patch should prevent the exception:

Index: SyslogWriter.java
===================================================================
--- SyslogWriter.java   (revision 321351)
+++ SyslogWriter.java   (working copy)
@@ -79,7 +79,7 @@
     DatagramPacket packet =
       new DatagramPacket(bytes, bytes.length, address, SYSLOG_PORT);
   
-    if (this.ds != null) {
+    if (this.ds != null && this.address != null) {
       ds.send(packet);
     }
     // clean up for next time

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org