[jcifs] Bug in jCIFS 0.8.0 SmbFile.exists() method
Michael Kerley
michael at enkoo.com
Wed Feb 25 23:26:17 GMT 2004
I found a bug in the exists() method in jCIFS 0.8.0. If I create an
SmbFile representing a workgroup and call exists() on it, it always
returns false (which is wrong). However, if I create the file, call
length(), and then call exists(), it returns true. This problem only
happens in version 0.8.0 (didn't test with 0.8.0b, but all 0.7.x
versions seemed fine). Also, the problem only seems to happen with
domains. If I call exists() on a server or a file, it works fine.
The following example is a modification of the Exists.java example
program that comes with jCIFS. I've also included sample output showing
the bug (first using version 0.7.19, then using 0.8.0).
I hope this example helps solve the bug. Keep up the good work.
Michael Kerley
------ BEGIN EXAMPLE CODE ------
import jcifs.smb.SmbFile;
public class Exists {
public static void main( String argv[] ) throws Exception {
System.out.println( "Method 1: call length() first" );
exists1( argv[0] );
System.out.println();
System.out.println( "Method 2: do not call length() first" );
exists2( argv[0] );
}
public static void exists1( String filename ) throws Exception {
SmbFile f = new SmbFile( filename );
System.out.println( f.length() + " bytes" ); // check the length
first
if( f.exists() ) {
System.out.println( filename + " exists" );
} else {
System.out.println( filename + " does not exist" );
}
}
public static void exists2( String filename ) throws Exception {
SmbFile f = new SmbFile( filename );
// don't check the length first
if( f.exists() ) {
System.out.println( filename + " exists" );
} else {
System.out.println( filename + " does not exist" );
}
}
}
------ END EXAMPLE CODE ------
------ BEGIN EXAMPLE OUTPUT ------
C:\java\jcifs_0.8.0\examples>set
classpath=.;c:\java\jcifs_0.7.19\jcifs-0.7.19.jar
C:\java\jcifs_0.8.0\examples>java Exists smb://mydomain/
Method 1: call length() first
0 bytes
smb://mydomain/ exists
Method 2: do not call length() first
smb://mydomain/ exists
C:\java\jcifs_0.8.0\examples>set
classpath=.;c:\java\jcifs_0.8.0\jcifs-0.8.0.jar
C:\java\jcifs_0.8.0\examples>java Exists smb://mydomain/
Method 1: call length() first
0 bytes
smb://mydomain/ exists
Method 2: do not call length() first
smb://mydomain/ does not exist
------ END EXAMPLE OUTPUT ------
More information about the jcifs
mailing list