commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nathan Beyer (JIRA)" <j...@apache.org>
Subject [jira] Commented: (NET-168) NullPointerException in TelnetClient.disconnect() while being connected
Date Sat, 03 Nov 2007 20:06:50 GMT

    [ https://issues.apache.org/jira/browse/NET-168?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12539981
] 

Nathan Beyer commented on NET-168:
----------------------------------

You can call disconnect from another thread, but you must do so exclusive of any other interaction
on the FTPClient instance. You must synchronize access. You may be able to do this sort of
thing with java.net.Socket, but it likely has some form of internal synchronization to protect
things; however, there's no mention of this in the javadoc, so I wouldn't make any assumptions
about that.

In any case, what you'll want to do is something like this.

// create a final lock object to synchronize access to the 'ftpCon' field
private FTPClient ftpCon = null;
private final Object ftpConLock = new Object();

public void testHandler() {
    ...
    // synchronize every access to the field
    synchronized(ftpConLock) {
        ftpCon = new FTPClient();
        ...
    }
   ...
}

public void interrupt() {
   synchronized(ftpConLock) {
      if (ftpCon != null && ftpCon.isConnected()) {
         ftpCon.disconnect();
      }
   }
}

> NullPointerException in TelnetClient.disconnect() while being connected
> -----------------------------------------------------------------------
>
>                 Key: NET-168
>                 URL: https://issues.apache.org/jira/browse/NET-168
>             Project: Commons Net
>          Issue Type: Bug
>    Affects Versions: 1.4
>         Environment: Debian GNU/Linux, FedoraCore, RedHat
>            Reporter: Kamil
>
> java.lang.NullPointerException
> org.apache.commons.net.telnet.TelnetClient.disconnect(TelnetClient.java:125)
> org.apache.commons.net.ftp.FTP.disconnect(FTP.java:397)
> org.apache.commons.net.ftp.FTPClient.disconnect(FTPClient.java:590)
> This exception occurs when trying to invoke myFTPClient.disconnect() method, when ftpclient
hangs for a long time and dont want to connect...

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message