#vulnerable code 
                                public void test() throws Exception {
        String imagesFolderPath = FilenameUtils
                .separatorsToSystem("src\\test\\data\\images\\png\\3");
        File imagesFolder = new File(imagesFolderPath);
        assertTrue(imagesFolder.exists() && imagesFolder.isDirectory());

        File files[] = imagesFolder.listFiles();
        for (int i = 0; i < files.length; i++) {
            File imageFile = files[i];
            if (!imageFile.isFile())
                continue;
            if (!imageFile.getName().toLowerCase().endsWith(".png"))
                continue;

            Debug.debug();
            Debug.debug("imageFile", imageFile);

            File lastFile = imageFile;
            for (int j = 0; j < 10; j++) {
                Map<String,Object> readParams = new HashMap<String,Object>();
                // readParams.put(SanselanConstants.BUFFERED_IMAGE_FACTORY,
                // new RgbBufferedImageFactory());
                BufferedImage image = Imaging.getBufferedImage(lastFile,
                        readParams);
                assertNotNull(image);

                File tempFile = createTempFile(imageFile.getName() + "." + j
                        + ".", ".png");
                Debug.debug("tempFile", tempFile);

                Map<String,Object> writeParams = new HashMap<String,Object>();
                Imaging.writeImage(image, tempFile,
                        ImageFormat.IMAGE_FORMAT_PNG, writeParams);

                lastFile = tempFile;
            }
        }
    } 
                            #location 8 
                            #vulnerability type NULL_DEREFERENCE
#fixed code
                                public void test() throws Exception {
        String imagesFolderPath = FilenameUtils
                .separatorsToSystem("src\\test\\data\\images\\png\\3");
        File imagesFolder = new File(imagesFolderPath);
        assertTrue(imagesFolder.exists() && imagesFolder.isDirectory());

        File files[] = imagesFolder.listFiles();
        for (File file : files) {
            File imageFile = file;
            if (!imageFile.isFile())
                continue;
            if (!imageFile.getName().toLowerCase().endsWith(".png"))
                continue;

            Debug.debug();
            Debug.debug("imageFile", imageFile);

            File lastFile = imageFile;
            for (int j = 0; j < 10; j++) {
                Map<String,Object> readParams = new HashMap<String,Object>();
                // readParams.put(SanselanConstants.BUFFERED_IMAGE_FACTORY,
                // new RgbBufferedImageFactory());
                BufferedImage image = Imaging.getBufferedImage(lastFile,
                        readParams);
                assertNotNull(image);

                File tempFile = createTempFile(imageFile.getName() + "." + j
                        + ".", ".png");
                Debug.debug("tempFile", tempFile);

                Map<String,Object> writeParams = new HashMap<String,Object>();
                Imaging.writeImage(image, tempFile,
                        ImageFormat.IMAGE_FORMAT_PNG, writeParams);

                lastFile = tempFile;
            }
        }
    }