Re: NullPointerException at listFiles

Michael B Allen <[email protected]>
Newsgroups gmane.network.samba.java
Message-ID <CAGMFw4i3oJiEzLW3uu2fue3dpof_yR7ZXWDNcJifxrVCiSO1jA@mail.gmail.com>
On Fri, Mar 2, 2012 at 5:53 AM, Gabor Herr <[email protected]> wrote:
> Hi All,
>
> we encountered the same problem as Dora reported
> https://lists.samba.org/archive/jcifs/2012-January/009856.html with
> jcifs-1.3.16 in a different usage scenario. We have a component that
> periodically polls a remote directory with listFiles. The
> NullPointerException occurs irregularly during the day but quite often about
> every 5-10 minutes. We figured out, that the root cause was an I/O Exception
> due to timeout on the socket transport level, probably because the remote
> server has not responded or the network connection failed. As Mike mentioned
> in his post, there is a problem in jcifs implementation that tconHostName is
> explicitly set to null, when a transport exception is thrown. On a reconnect
> attempt in Dfs.resolve() the NPE is thrown, because tconHostName is null.
>
> The following patch fixed the problem for us. We changed the finally block
> to not clear tconHostName and added code to the constructor to ensure, that
>  it always contains a valid hostname.
>
> Index: C:/Documents and Settings/kjr130/My
> Documents/Downloads/jcifs_1.3.16.orig/jcifs-1.3.16.orig/src/jcifs/smb/SmbTransport.java
> ===================================================================
> --- C:/Documents and Settings/kjr130/My
> Documents/Downloads/jcifs_1.3.16.orig/jcifs-1.3.16.orig/src/jcifs/smb/SmbTransport.java
>        (revision 632)
> +++ C:/Documents and Settings/kjr130/My
> Documents/Downloads/jcifs_1.3.16.orig/jcifs-1.3.16.orig/src/jcifs/smb/SmbTransport.java
>        (working copy)
> @@ -114,6 +114,9 @@
>          this.port = port;
>          this.localAddr = localAddr;
>          this.localPort = localPort;
> +        if (address != null) {
> +                this.tconHostName = address.getHostName();
> +        }

Hi Gabor,

I don't think it's a good idea to set the tconHostName in the constructor.

Please post the full NPE stack trace.

Mike

>      }
>
>      synchronized SmbSession getSmbSession() {
> @@ -371,7 +374,7 @@
>          } finally {
>              digest = null;
>              socket = null;
> -            tconHostName = null;
> +//            tconHostName = null;
>          }
>      }
>
> I would greatly appreciate, if you could include this fix into upcoming
> jcifs releases.
>
> Thanks.
>
> Gabor



-- 
Michael B Allen
Java Active Directory Integration
http://www.ioplex.com/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.