<div class="gmail_quote">2012/3/5 Michael B Allen <span dir="ltr"><<a href="mailto:ioplex@gmail.com" target="_blank">ioplex@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div><div><br>
</div></div>Hi Gabor,<br>
<br>
I don't think it's a good idea to set the tconHostName in the constructor.<br>
<br>
Please post the full NPE stack trace.<br>
<br>
Mike<br>
<div><div><br></div></div></blockquote><div class="gmail_quote"><br></div>Hi Mike,<div><br></div><div>the stack trace is exactly the same as reported by Dora:</div><div><br></div><div><font color="#000080" face="Courier New"><u>java.lang.NullPointerException</u></font><span> </span><br>

<font color="red" face="Courier New">        at jcifs.smb.Dfs.resolve(</font><font color="#000080" face="Courier New"><u>Dfs.java:169</u></font><font color="red" face="Courier New">)</font><span> </span><br>
<font color="red" face="Courier New">        at jcifs.smb.SmbFile.resolveDfs(</font><font color="#000080" face="Courier New"><u>SmbFile.java:671</u></font><font color="red" face="Courier New">)</font><span> </span><br>
<font color="red" face="Courier New">        at jcifs.smb.SmbFile.send(</font><font color="#000080" face="Courier New"><u>SmbFile.java:773</u></font><font color="red" face="Courier New">)</font><span> </span><br>
<font color="red" face="Courier New">        at jcifs.smb.SmbFile.doFindFirstNext(</font><font color="#000080" face="Courier New"><u>SmbFile.java:1986</u></font><font color="red" face="Courier New">)</font><span> </span><br>

<font color="red" face="Courier New">        at jcifs.smb.SmbFile.doEnum(</font><font color="#000080" face="Courier New"><u>SmbFile.java:1738</u></font><font color="red" face="Courier New">)</font><span> </span><br>
<font color="red" face="Courier New">        at jcifs.smb.SmbFile.listFiles(</font><font color="#000080" face="Courier New"><u>SmbFile.java:1715</u></font><font color="red" face="Courier New">)</font><span> </span><br>
<font color="red" face="Courier New">        at jcifs.smb.SmbFile.listFiles(</font><font color="#000080" face="Courier New"><u>SmbFile.java:1648</u></font><font color="red" face="Courier New">)</font><span> </span><br>
<font color="red" face="Courier New">        at Test$Browser.run(</font><font color="#000080" face="Courier New"><u>Test.java:25</u></font><font color="red" face="Courier New">)</font><span> </span><br>
<font color="red" face="Courier New">        at java.lang.Thread.run(</font><font color="#000080" face="Courier New"><u>Thread.java:662</u></font><font color="red" face="Courier New">)</font><font face="sans-serif"><br>
</font><br></div><div>At first we only changed the finally block, but that did not fix the problem. Only after setting tconHostName in the constructor jcifs was able to recover from a temporary connection loss. We use the following test code to reproduce the problem:</div>
<div><br></div><div><font size="2" face="sans-serif" style>Test.java:</font><span style> </span><br style>---------------------------------------------------------------------------------------------------------------------------------------------------------------<br style>
<font size="2" face="sans-serif" style>import jcifs.smb.NtlmPasswordAuthentication;</font><span style> </span><br style><font size="2" face="sans-serif" style>import jcifs.smb.SmbFile;</font><span style> </span><br style>
<br style><br style><font size="2" face="sans-serif" style>public class Test {</font><span style> </span><br style><font size="2" face="sans-serif" style>        </font><span style></span><br style><font size="2" face="sans-serif" style>        public class Browser implements Runnable {</font><span style> </span><br style>
<font size="2" face="sans-serif" style>                </font><span style></span><br style><font size="2" face="sans-serif" style>                private int id;</font><span style> </span><br style><font size="2" face="sans-serif" style>                </font><span style></span><br style>
<font size="2" face="sans-serif" style>                public Browser(int n) {</font><span style> </span><br style><font size="2" face="sans-serif" style>                        id = n;</font><span style> </span><br style>
<font size="2" face="sans-serif" style>                }</font><span style> </span><br style><font size="2" face="sans-serif" style>                </font><span style></span><br style><font size="2" face="sans-serif" style>                @Override</font><span style> </span><br style>
<font size="2" face="sans-serif" style>                public void run() {</font><span style> </span><br style><font size="2" face="sans-serif" style>                        for (int n = 0; n < 1000; n++) {</font><span style> </span><br style>
<font size="2" face="sans-serif" style>                                NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("domain", "user", "passwd");</font><span style> </span><br style>
<font size="2" face="sans-serif" style>                                </font><span style></span><br style><font size="2" face="sans-serif" style>                                try {</font><span style> </span><br style><font size="2" face="sans-serif" style>                                        System.out.println("Thread " + id + " browsing folder.");</font><span style> </span><br style>
<font size="2" face="sans-serif" style>                                        </font><span style></span><br style><font size="2" face="sans-serif" style>                                        SmbFile file = new SmbFile("smb://server/dir/", auth);</font><span style> </span><br style>
<font size="2" face="sans-serif" style>                                        </font><span style></span><br style><font size="2" face="sans-serif" style>                                        file.listFiles();</font><span style> </span><br style>
<font size="2" face="sans-serif" style>                                } catch (Exception e) {</font><span style> </span><br style><font size="2" face="sans-serif" style>                                        e.printStackTrace();</font><span style> </span><br style>
<font size="2" face="sans-serif" style>                                }</font><span style> </span><br style><font size="2" face="sans-serif" style>                        }</font><span style> </span><br style><font size="2" face="sans-serif" style>                }                </font><span style> </span><br style>
<font size="2" face="sans-serif" style>        }</font><span style> </span><br style><br style><font size="2" face="sans-serif" style>        public static void main(String[] args) {</font><span style> </span><br style><font size="2" face="sans-serif" style>                new Test().run();</font><span style> </span><br style>
<font size="2" face="sans-serif" style>        }</font><span style> </span><br style><font size="2" face="sans-serif" style>        </font><span style></span><br style><font size="2" face="sans-serif" style>        public void run() {</font><span style> </span><br style>
<font size="2" face="sans-serif" style>                try {</font><span style> </span><br style><font size="2" face="sans-serif" style>                        jcifs.Config.setProperty( "jcifs.netbios.wins", "XX.XX.XX.XX" );</font><span style> </span><br style>
<font size="2" face="sans-serif" style>                        </font><span style></span><br style><font size="2" face="sans-serif" style>                        for (int n = 0; n < 50; n++) {</font><span style> </span><br style>
<font size="2" face="sans-serif" style>                                new Thread(new Browser(n)).start();</font><span style> </span><br style><font size="2" face="sans-serif" style>                                Thread.sleep(200);</font><span style> </span><br style>
<font size="2" face="sans-serif" style>                        }</font><span style> </span><br style><font size="2" face="sans-serif" style>                } catch (Exception e) {</font><span style> </span><br style><font size="2" face="sans-serif" style>                        e.printStackTrace();</font><span style> </span><br style>
<font size="2" face="sans-serif" style>                }</font><span style> </span><br style><font size="2" face="sans-serif" style>        }</font><span style> </span><br style><font size="2" face="sans-serif" style>}</font></div>
<div><font size="2" face="sans-serif" style>-------------------------------------------------------------------------------------------------------------------------------------------------------------</font></div><div><font color="#222222" face="sans-serif"><br>
</font></div><div><font color="#222222" face="sans-serif">The multiple theads are needed to create a significant load. While the test case is running, we simulate a network error by simply pulling the network cable and reconnect it again. Without the changes I've posted jcifs cannot recover and persistently throws NPEs at Dfs.resolve, because tconHostName is null. With both changes applied, the connection is recovered and no exception is thrown, no matter how often we interrupt the connection. </font></div>
<div><font color="#222222" face="sans-serif"><br></font></div><div><font color="#222222" face="sans-serif">Setting tconHostName in the constructor ensures, that it is matching the IP address, which is also stored there. In a reconnect attempt the host name is not passed in, that's why the error occurs.</font></div>
<div><font color="#222222" face="sans-serif"><br></font></div></div>