[jcifs] NullPointerException when doing SmbFile.listFiles()

Arjan van der Veen avdveen at palanthir.nl
Thu Mar 5 19:43:55 GMT 2009


I have just been debugging and got it working. I am not sure if this is the
real solution, since the resp.lastName is null in the response object (and I
don't know why), but this is the workaround I made:In the file SmbFile.java
I made the following change:

    void doFindFirstNext( ArrayList list,
                boolean files,
                String wildcard,
                int searchAttributes,
                SmbFilenameFilter fnf,
                SmbFileFilter ff ) throws SmbException,
UnknownHostException, MalformedURLException {
        SmbComTransaction req;
        Trans2FindFirst2Response resp;
        int sid;
        String path = getUncPath0();
        String p = url.getPath();

        if( p.lastIndexOf( '/' ) != ( p.length() - 1 )) {
            throw new SmbException( url.toString() + " directory must end
with '/'" );
        }

        req = new Trans2FindFirst2( path, wildcard, searchAttributes );
        resp = new Trans2FindFirst2Response();

        if( log.level >= 3 )
            log.println( "doFindFirstNext: " + req.path );

        send( req, resp );

        sid = resp.sid;

        /* The only difference between first2 and next2 responses is
subCommand
         * so let's recycle the response object.
         */
        resp.subCommand = SmbComTransaction.TRANS2_FIND_NEXT2;

        for( ;; ) {
            String lastName = null;
            for( int i = 0; i < resp.numEntries; i++ ) {
                FileEntry e = resp.results[i];
                String name = e.getName();
                lastName = name;
                if( name.length() < 3 ) {
                    int h = name.hashCode();
                    if( h == HASH_DOT || h == HASH_DOT_DOT ) {
                        if (name.equals(".") || name.equals(".."))
                            continue;
                    }
                }
                if( fnf != null && fnf.accept( this, name ) == false ) {
                    continue;
                }
                if( name.length() > 0 ) {
                    SmbFile f = new SmbFile( this, name, TYPE_FILESYSTEM,
                            e.getAttributes(), e.createTime(),
e.lastModified(), e.length() );
                    if( ff != null && ff.accept( f ) == false ) {
                        continue;
                    }
                    if( files ) {
                        list.add( f );
                    } else {
                        list.add( name );
                    }
                }
            }

            if( resp.isEndOfSearch || resp.numEntries == 0 ) {
                break;
            }

            req = new Trans2FindNext2( sid, resp.resumeKey, lastName );
            req.reset( resp.resumeKey, lastName );
            resp.reset();
            send( req, resp );
        }

        try {
            send( new SmbComFindClose2( sid ), blank_resp() );
        } catch (SmbException se) {
            if( log.level >= 4 )
                se.printStackTrace( log );
        }
    }

Is this a work-around or the solution of the bug?

Best regards,

Arjan van der Veen



On Thu, Mar 5, 2009 at 17:44, Michael B Allen <ioplex at gmail.com> wrote:

> On Thu, Mar 5, 2009 at 10:19 AM, Arjan van der Veen
> <avdveen at palanthir.nl> wrote:
> >         smbFile = new SmbFile(smbFile.getParent(), auth);
> >         smbFile.list();
> > The reading of the file works perfect, the listing of the subfile of a
> > directory results in the following stacktrace:
> > Testcase:
> > testInitialCrawling(nl.palanthir.enterprise.indexer.CifsCrawlerTest):
> >  Caused an ERROR
> > null
> > java.lang.NullPointerException
> >         at
> > jcifs.smb.ServerMessageBlock.writeString(ServerMessageBlock.java:213)
> >         at
> > jcifs.smb.ServerMessageBlock.writeString(ServerMessageBlock.java:202)
> >         at
> >
> jcifs.smb.Trans2FindNext2.writeParametersWireFormat(Trans2FindNext2.java:67)
> >         at
> > jcifs.smb.SmbComTransaction.nextElement(SmbComTransaction.java:121)
> >         at jcifs.smb.SmbTransport.send(SmbTransport.java:577)
>
> Looks like a bug. Somehow the filename is becoming null.
>
> I've made a note of it. Will fix.
>
> Thanks,
> Mike
>
> --
> Michael B Allen
> Java Active Directory Integration
> http://www.ioplex.com/
>



-- 
--
Palanthir BV
Arjan van der Veen
Krepelsbosch 129
7325AP Apeldoorn
+31655730384
avdveen at palanthir.nl
-------------- next part --------------
HTML attachment scrubbed and removed


More information about the jcifs mailing list