[jcifs] java.lang.NullPointerException

Daniel Rychlik drychlik at securustech.net
Sat Nov 4 15:58:42 GMT 2006


Hello,

I have searched through the mailing list for this problem and have not found a solution to it yet.

I am having an issue that doesn$B!G(Jt make sense to me.  I have gotten this code to work exceptionally well under my netbeans IDE environment but after I build my project, with the JCIFS jar, I get a java.lang.NullPointerException.  Works fine in editor when testing, but fails when I put in production$B!D(J  

Here is a simple class that I use to check a directory structure and if it doesn$B!G(Jt exists it creates it, and then it copies a list of files which are stored in a LinkedList.  I do a lot of automation and have hundreds of NT, 2K, XP systems in the field.  Some of which are dialup$B!D(J  $B"+(J fun.

Never the less I tried to put this in production last night and ran across this very annoying problem with the null pointer exception.  Has anyone run into this before?

Here is class I coded.  I basically took the examples and expanded up on those to fit my needs.  My servers are windows 2003, my build machine is XP.  Like I said it works like a champ in the Netbeans IDE environment when I am building and testing, but when its all wrapped in a Jar it fails$B!D(J  

public class smbFileHandler {
    
    private LinkedList<String> smbHandlerLog = new LinkedList<String>();
    
    // Getter for the log
    public LinkedList getSmbHandlerLog()
    {
        return smbHandlerLog;
    }
    
    /** Creates a new instance of smbFileHandler */
    public smbFileHandler()
    {
    }

    // SMB File handler Manager
    public void smbFileManager(String smbConn,String[] directories,LinkedList files) throws Exception
    {
        System.out.println("(SMB FILE MANAGER) " + smbConn);
        
        try 
        {
            // Check the remote directory structure
            for (int i = 0; i < directories.length; i++)
            {
                if (!smbFileExists(smbConn + directories[i]))
                {
                    new SmbFile(smbConn + directories[i]).mkdir();
                }
            }

            // Process the files in the programs List
            String[] data = new String[3];

            for (Object s: files)
            {
                data = s.toString().split(",");

                if (data[2].equals("check"))
                {
                    if (!smbFileExists(data[1]))
                    {
                        smbFileWrite(data[0],data[1]);
                    }
                } 
                else 
                {
                    smbFileWrite(data[0],data[1]);
                }
            }
        } catch (Exception e)
        {
            System.out.println("SMB EXCEPTION " + e.toString());
            throw new Exception("93" + e.toString());
        }
    }
    
    // SMB File Exists
    private boolean smbFileExists(String file) throws Exception
    {
        
        System.out.println("Exists ? " + file);
        
        try 
        {
            SmbFile f = new SmbFile(file);

            if( f.exists() ) {
                System.out.println( file + " exists" );
                return true;
            } else {
                System.out.println( file + " does not exist" );
                return false;
            }
        } catch (Exception e)
        {
            System.out.println("SMB FILE EXITS EXCEPTION " + e.toString());
            throw new Exception("93" + e.toString());
        }
    }
    
    // Write the file using smb protocol
    private void smbFileWrite(String sourceFile, String destinationFile) throws Exception
    {
        try 
        {
            System.out.println("Source File " + sourceFile);
            System.out.println("Destination File " + destinationFile);

            SmbFile f = new SmbFile(destinationFile);
            FileInputStream in = new FileInputStream(sourceFile);
            SmbFileOutputStream out = new SmbFileOutputStream( f );

            long t0 = System.currentTimeMillis();

            byte[] b = new byte[512];
            
            int n, tot = 0;
            
            while(( n = in.read( b )) > 0 ) {
                out.write( b, 0, n );
                tot += n;
            }

            long t = System.currentTimeMillis() - t0;

            System.out.println();
            System.out.println( tot + " bytes transfered in " + ( t / 1000 ) + " seconds at " + (( tot / 1000 ) / Math.max( 1, ( t / 1000 ))) + "Kbytes/sec" );

            in.close();
            out.close();
        } catch (Exception e)
        {
            throw new Exception("93" + e.toString());
        }
    }
}






More information about the jcifs mailing list