Re: NullPointerException at listFiles

Gabor Herr <[email protected]>
Newsgroups gmane.network.samba.java
Message-ID <CACH_Ci9tHj82yYkRUxW1W0h0uA9SP7Rb=kwBkGr-GqrOkAdPuA@mail.gmail.com>
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();
+        }
     }

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