#fixed code
                                public static String downloadFile(String url, String dir, String filename) throws Exception {
        log.info("start download file :{}",url);
        //Open a URL Stream
        Connection.Response resultResponse = Jsoup.connect(url)
                .userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3346.9 Safari/537.36")
                .ignoreContentType(true).execute();
        String defaultFileName="";
        if(resultResponse.contentType().contains("name")){
            String[] list =resultResponse.contentType().split(";");
            defaultFileName = Arrays.stream(list)
                    .filter(s -> s.startsWith("name")).findFirst().get().replaceAll("name=|\"", "");
        }
        // output here
        String path = dir + (null == filename ? defaultFileName : filename);
        FileOutputStream out=null;
       try{
            out = (new FileOutputStream(new java.io.File(path)));
           out.write(resultResponse.bodyAsBytes());
       }catch (Exception ex){
           log.error("{}",ex);
           ex.printStackTrace();
       }finally {
           out.close();
       }
        return path;
    }
#vulnerable code 
                                public static String downloadFile(String url, String dir, String filename) throws Exception {
        log.info("start download file :{}",url);
        //Open a URL Stream
        Connection.Response resultResponse = Jsoup.connect(url)
                .userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3346.9 Safari/537.36")
                .ignoreContentType(true).execute();
        String defaultFileName="";
        if(resultResponse.contentType().contains("name")){
            String[] list =resultResponse.contentType().split(";");
            defaultFileName = Arrays.stream(list)
                    .filter(s -> s.startsWith("name")).findFirst().get().replaceAll("name=|\"", "");
        }
        // output here
        String path = dir + (null == filename ? defaultFileName : filename);
        FileOutputStream out = (new FileOutputStream(new java.io.File(path)));
        out.write(resultResponse.bodyAsBytes());
        out.close();
        return path;
    } 
                            #location 18 
                            #vulnerability type RESOURCE_LEAK