[jcifs] NullPointerException]

Michael B Allen mba2000 at ioplex.com
Sat Jun 5 00:25:45 GMT 2004


Eric said:
>
>>
>> I don't think we can do that. At least not consistently. Many of the
>> SmbFile constructors call the java.net.URL constructor in a way that
>> would
>> make it difficult if not impossible to intercept this condition. I could
>> be wrong but I think it would probably introduce more trouble than it's
>> worth.
>>
>
> It could be done fairly easily by replacing prior to passing the string
> to the URL constructor (see attached).  So you could do:
>
>       SmbFile("\\\\server\\share\\dir\\file.txt");
>
> or:
>
>       SmbFile("\\\\user:password at server\\share\\");
>
> or even "mix and match", i.e.:
>
>       SmbFile("\\\\server\\", "share/dir/file.txt");
>       SmbFile("smb://server/share/", "dir\\file.txt");

Yeah, but all constructors except one do stuff like this:

    public SmbFile( String url ) throws MalformedURLException {
        this( new URL( null, url, Handler.SMB_HANDLER ));
    }

You cannot have any code before the this() call so you would need to call
a method or do some screwy stuff with a ternary operator.

    static final String uncconv( String url ) {
        if( url.startsWith( "\\\\" )) {
            return "smb:" + url.replace( '\\', '/' );
        }
        return url;
    }

    public SmbFile( String url ) throws MalformedURLException {
        this( new URL( null, uncconv( url ), Handler.SMB_HANDLER ));
    }

Maybe AbstractFile would be a better place for this.

Mike


More information about the jcifs mailing list