[jcifs] NullPointerException at listFiles

Gabor Herr gabor.e.herr at googlemail.com
Fri Mar 2 03:53:55 MST 2012


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.samba.org/pipermail/jcifs/attachments/20120302/661133eb/attachment.html>


More information about the jCIFS mailing list