#fixed code
                              public static void main(String[] args) throws Exception {
    long curTime = System.nanoTime();
    SearchArgs searchArgs = new SearchArgs();
    CmdLineParser parser = new CmdLineParser(searchArgs, ParserProperties.defaults().withUsageWidth(90));

    try {
      parser.parseArgument(args);
    } catch (CmdLineException e) {
      System.err.println(e.getMessage());
      parser.printUsage(System.err);
      System.err.println("Example: SearchGov2" + parser.printExample(OptionHandlerFilter.REQUIRED));
      return;
    }

    Path topicsFile = Paths.get(searchArgs.topics);

    LOG.info("Reading index at " + searchArgs.index);
    Directory dir;
    if (searchArgs.inmem) {
      LOG.info("Using MMapDirectory with preload");
      dir = new MMapDirectory(Paths.get(searchArgs.index));
      ((MMapDirectory) dir).setPreload(true);
    } else {
      LOG.info("Using default FSDirectory");
      dir = FSDirectory.open(Paths.get(searchArgs.index));
    }

    IndexReader reader = DirectoryReader.open(dir);
    IndexSearcher searcher = new IndexSearcher(reader);

    if (searchArgs.ql) {
      LOG.info("Using QL scoring model");
      searcher.setSimilarity(new LMDirichletSimilarity(2500.0f));
    } else if (searchArgs.rm3) {
      LOG.info("Using RM3 query expansion");
      searcher.setSimilarity(new BM25Similarity(0.9f, 0.4f));
    } else if (searchArgs.bm25) {
      LOG.info("Using BM25 scoring model");
      searcher.setSimilarity(new BM25Similarity(0.9f, 0.4f));
    } else {
      LOG.error("Error: Must specify scoring model!");
      System.exit(-1);
    }

    int maxResults = 1000;

    TrecTopicsReader qReader = new TrecTopicsReader();
    QualityQuery qqs[] = qReader.readQueries(Files.newBufferedReader(topicsFile, StandardCharsets.UTF_8));

    PrintStream out = new PrintStream(new FileOutputStream(new File(searchArgs.output)));
    LOG.info("Writing output to " + searchArgs.output);

    LOG.info("Initialized complete! (elapsed time = " + (System.nanoTime()-curTime)/1000000 + "ms)");
    long totalTime = 0;
    for (QualityQuery qq : qqs) {
      long curQueryTime = System.nanoTime();
      Query query = AnalyzerUtils.buildBagOfWordsQuery("body", new EnglishAnalyzer(), qq.getValue("title"));
      TopDocs rs = searcher.search(query, maxResults);

      RerankerContext context = new RerankerContext(searcher, query, qq.getValue("title"), null);
      RerankerCascade cascade = new RerankerCascade(context);

      if (searchArgs.rm3) {
        cascade.add(new Rm3Reranker(new EnglishAnalyzer(), "body"));
      } else {
        cascade.add(new IdentityReranker());
      }

      ScoredDocuments docs = cascade.run(ScoredDocuments.fromTopDocs(rs, searcher));

      for (int i=0; i<docs.documents.length; i++) {
        String qid = qq.getQueryID();
        out.println(String.format("%s Q0 %s %d %f %s", qid,
            docs.documents[i].getField("docid").stringValue(), (i+1), docs.scores[i], "Lucene"));
      }
      long qtime = (System.nanoTime()-curQueryTime)/1000000;
      LOG.info("Query " + qq.getQueryID() + " (elapsed time = " + qtime + "ms)");
      totalTime += qtime;
    }

    LOG.info("All queries completed!");
    LOG.info("Total elapsed time = " + totalTime + "ms");
    LOG.info("Average query latency = " + (totalTime/qqs.length) + "ms");

    reader.close();
    dir.close();
    out.close();
  }
#vulnerable code 
                              public static void main(String[] args) throws Exception {

    if (args.length < 4 || args.length > 5) {
      System.err.println("Usage: QueryDriver <topicsFile> <qrelsFile> <submissionFile> <indexDir> [querySpec]");
      System.err.println("topicsFile: input file containing queries");
      System.err.println("qrelsFile: input file containing relevance judgements");
      System.err.println("submissionFile: output submission file for trec_eval");
      System.err.println("indexDir: index directory");
      System.err.println("querySpec: string composed of fields to use in query consisting of T=title,D=description,N=narrative:");
      System.err.println("\texample: TD (query on Title + Description). The default is T (title only)");
      System.exit(1);
    }

    Path topicsFile = Paths.get(args[0]);
    Path qrelsFile = Paths.get(args[1]);
    Path submissionFile = Paths.get(args[2]);
    SubmissionReport submitLog = new SubmissionReport(new PrintWriter(Files.newBufferedWriter(submissionFile, StandardCharsets.UTF_8)), "lucene");
    MMapDirectory dir = new MMapDirectory(Paths.get(args[3]));
    dir.setPreload(true);
    String fieldSpec = args.length == 5 ? args[4] : "T"; // default to Title-only if not specified.
    IndexReader reader = DirectoryReader.open(dir);
    IndexSearcher searcher = new IndexSearcher(reader);

    searcher.setSimilarity(new BM25Similarity(0.9f, 0.4f));
    //searcher.setSimilarity(new LMDirichletSimilarity(2500.0f));

    int maxResults = 1000;
    String docNameField = "docid";

    PrintWriter logger = new PrintWriter(new OutputStreamWriter(System.out, Charset.defaultCharset()), true);

    // use trec utilities to read trec topics into quality queries
    TrecTopicsReader qReader = new TrecTopicsReader();
    QualityQuery qqs[] = qReader.readQueries(Files.newBufferedReader(topicsFile, StandardCharsets.UTF_8));

    // prepare judge, with trec utilities that read from a QRels file
    //Judge judge = new TrecJudge(Files.newBufferedReader(qrelsFile, StandardCharsets.UTF_8));

    // validate topics & judgments match each other
    //judge.validateData(qqs, logger);

    Set<String> fieldSet = new HashSet<>();
    if (fieldSpec.indexOf('T') >= 0) fieldSet.add("title");
    if (fieldSpec.indexOf('D') >= 0) fieldSet.add("description");
    if (fieldSpec.indexOf('N') >= 0) fieldSet.add("narrative");

    // set the parsing of quality queries into Lucene queries.
    QualityQueryParser qqParser = new EnglishQQParser(fieldSet.toArray(new String[0]), "body");

    PrintStream out = new PrintStream(System.out, true, "UTF-8");

    for (QualityQuery qq : qqs) {
      //System.out.println(qq.getValue("title"));
      
      Query query = AnalyzerUtils.buildBagOfWordsQuery("body", new EnglishAnalyzer(), qq.getValue("title"));
      //System.out.println(query);
      TopDocs rs = searcher.search(query, maxResults);

      RerankerContext context = new RerankerContext(searcher, query, qq.getValue("title"), null);
      RerankerCascade cascade = new RerankerCascade(context);

      cascade.add(new Rm3Reranker(new EnglishAnalyzer(), "body"));

      ScoredDocuments docs = cascade.run(ScoredDocuments.fromTopDocs(rs, searcher));

      for (int i=0; i<docs.documents.length; i++) {
        String qid = qq.getQueryID();
        out.println(String.format("%s Q0 %s %d %f %s", qid,
            docs.documents[i].getField("docid").stringValue(), (i+1), docs.scores[i], "Lucene"));
      }
    }

//    // run the benchmark
//    QualityBenchmark qrun = new QualityBenchmark(qqs, qqParser, searcher, docNameField);
//    qrun.setMaxResults(maxResults);
//    QualityStats stats[] = qrun.execute(judge, submitLog, logger);
//
//    // print an avarage sum of the results
//    QualityStats avg = QualityStats.average(stats);
//    avg.log("SUMMARY", 2, logger, "  ");
    
    reader.close();
    dir.close();
    out.close();
  } 
                            #location 30 
                            #vulnerability type RESOURCE_LEAK