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=44109>.
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=44109

           Summary: Telnet Appender throws null pointers at log time when
                    socket couldn't be opened
           Product: Log4j
           Version: 1.2
          Platform: Other
        OS/Version: other
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Appender
        AssignedTo: [email protected]
        ReportedBy: [EMAIL PROTECTED]


The Telnet Appender seems to have a poorly designed start up sequence.  

Here is the activateOptions method:

/** all of the options have been set, create the socket handler and
      wait for connections. */
  public void activateOptions() {
    try {
      sh = new SocketHandler(port);
      sh.start();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
    super.activateOptions();
  }


If the socket handler fails to open the socket - say for instance - the port is
already in use - it will nearly silently eat the error - leaving itself
unconfigured.  If someone is trying to create a socket appender programatically,
they have no way of knowing if the activate step was successful or not.

I'm not sure how to fix this, since the AppenderSkeleton interface does not
allow the activateOptions method to throw exceptions.  Perhaps there should be a
new constructor that would take in all the options, do the work of the
activateOptions method, and throw the proper exceptions.  Or a getError()
method, or something.   

Worse - if the activateOptions() method fails, it leaves the sh variable null.

Look at what happens next:
 /** Handles a log event.  For this appender, that means writing the message to
each connected client.  */
  protected void append(LoggingEvent event) {
    sh.send(this.layout.format(event));


Hello, null pointer!  At log time, no less.  That code definitely needs a null
check.  Having a mis-configured appender shouldn't toss null pointers into the
logging sequence.

-- 
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to