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

           Summary: Telnet Appender misses messages
           Product: Log4j
           Version: 1.2
          Platform: Other
        OS/Version: other
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Appender
        AssignedTo: [email protected]
        ReportedBy: [EMAIL PROTECTED]


Using the newest 1.2 log4j, the TelnetAppender has an implementation mis-design
which causes it to not write messages to telnet sessions to random telnet
sessions after another telnet session has disconnected.

Here is the offending code:

    /** sends a message to each of the clients in telnet-friendly output. */
    public void send(String message) {
      Enumeration ce = connections.elements();
      for(Enumeration e = writers.elements();e.hasMoreElements();) {
        Socket sock = (Socket)ce.nextElement();
        PrintWriter writer = (PrintWriter)e.nextElement();
        writer.print(message);
        if(writer.checkError()) {
          // The client has closed the connection, remove it from our list:
          connections.remove(sock);
          writers.remove(writer);
        }
      }
    }

It is not safe to do a remove from a vector while you have an enumeration open
on it!  It results in the enumeration missing a valid element for each time you
call remove on the vector.

For example:

public static void main(String[] args) throws SocketException,
InterruptedException, URISyntaxException
{
        Vector temp = new Vector();
        temp.add("1");
        temp.add("2");
        temp.add("3");
        temp.add("4");
        Enumeration e = temp.elements();
        System.out.println(e.nextElement());
        Object o = e.nextElement();
        System.out.println(o);
        temp.remove(o);
        System.out.println(e.nextElement());
        System.out.println(e.nextElement());
}

The TelnetAppender code makes the assumption that this would print 1, 2, 3, and
4 to the console.  In fact, it prints 1, 2, 4 (and then takes and out of bounds
exception)

-- 
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