#vulnerable code 
                                Result scan() throws MojoExecutionException {
        // Scanning is lazy ...
        if (result == null) {
            if (!directory.exists()) {
                // No directory to check found so we return null here ...
                return null;
            }
            String[] jarOrWars = directory.list((dir, name) -> name.endsWith(".war") || name.endsWith(".jar"));
            if (jarOrWars == null || jarOrWars.length == 0) {
                return null;
            }
            long maxSize = 0;
            for (String jarOrWar : jarOrWars) {
                File archiveFile = new File(directory, jarOrWar);
                try {
                    JarFile archive = new JarFile(archiveFile);
                    Manifest mf = archive.getManifest();
                    Attributes mainAttributes = mf.getMainAttributes();
                    if (mainAttributes != null) {
                        String mainClass = mainAttributes.getValue("Main-Class");
                        if (mainClass != null) {
                            long size = archiveFile.length();
                            // Take the largest jar / war file found
                            if (size > maxSize) {
                                maxSize = size;
                                result = new Result(archiveFile, mainClass, mainAttributes);
                            }
                        }
                    }
                } catch (IOException e) {
                    throw new MojoExecutionException("Cannot examine file " + archiveFile + " for the manifest");
                }
            }
        }
        return result;
    } 
                            #location 17 
                            #vulnerability type RESOURCE_LEAK
#fixed code
                                FatJarDetector(String dir) {
        this.directory = new File(dir);
    }