[jcifs] NullPointerException at listFiles

Michael B Allen ioplex at gmail.com
Sat Jan 28 11:59:36 MST 2012

2012/1/28  <namadoray_curry at mail.goo.ne.jp>:
> Hi All,
> I recursively use SmbFile#listFiles method to access all folder and files.
> At first, the method correctly works.
> However I have the NullPointerException in about 10 minutes.
> This problem may be network environment.
> But if you have any ideas to modify this problem by setting up JCIFS property,
> teach me how to use the way.
> <environment>
> JCIFS : 1.3.16
> Network access : using DFS
> <stacktrace>
> java.util.NullPointerException
> at jcifs.smb.Dfs.resolve(Dfs.java:169)
> at jcifs.smb.SmbFile.resolveDfs(SmbFile.java:671)
> at jcifs.smb.SmbFile.send(SmbFile.java:773)
> at jcifs.smb.SmbFile.doFindFirstNext(SmbFile.java:1986)
> at jcifs.smb.SmbFile.doEnum(SmbFile.java:1738)
> at jcifs.smb.SmbFile.listFiles(SmbFile.java:1715)
> at jcifs.smb.SmbFile.listFiles(SmbFile.java:1704)

Hi Dora,

Does this help?


This looks like a logic error where the transport disconnects but
SmbFile is trying to reach down and touch something that is null
(tconHostName). Probably due to some other unrelated communications
error or more likely the transport just timed out. The above package
adds a check to help SmbFile know when the transport is disconnected
(so that it will re-open it appropriately). I was not able to
replicate this particular issue so please let us know if it actually
makes a difference.

Note that when crawling files, it's a good idea to do a
breadth-first-search with one file list that should be kept as small
as possible. If you do a typical depth-first-search you will end up
with multiple lists of potentially old paths. This is bound to result
in strange behavior and poor performance as you query a path and then
come back to it 10 minutes later only to find it is gone or the
transport to the server has been closed. Code should never throw an
NPE but a stale file list could be part of the problem you're seeing.


Michael B Allen
Java Active Directory Integration

More information about the jCIFS mailing list