#vulnerable code 
                              public static void main(String[] args) throws Exception {
    if (args.length < 1){
      System.out.println("usage: <index location> <command> <command args>");
      System.exit(1);
    }
    
    String idxLocation = args[0];
    
    ClueApplication app = null;
    
    if (args.length > 1){
      app = new ClueApplication(idxLocation, false);
      String cmd = args[1];
      String[] cmdArgs;
      cmdArgs = new String[args.length - 2];
      System.arraycopy(args, 2, cmdArgs, 0, cmdArgs.length);
      app.handleCommand(cmd, cmdArgs, System.out);
    }
    else{
      app = new ClueApplication(idxLocation, true);
      BufferedReader inReader = new BufferedReader(new InputStreamReader(System.in));
      while(true){
        System.out.print("> ");
        String line = inReader.readLine().trim();
        if (line.isEmpty()) continue;
        String[] parts = line.split("\\s");
        if (parts.length > 0){
          String cmd = parts[0];
          String[] cmdArgs = new String[parts.length - 1];
          System.arraycopy(parts, 1, cmdArgs, 0, cmdArgs.length);
          app.handleCommand(cmd, cmdArgs, System.out);
        }
      }
    }    
  } 
                            #location 5 
                            #vulnerability type RESOURCE_LEAK
#fixed code
                              public static void main(String[] args) throws Exception {
    if (args.length < 1){
      System.out.println("usage: <index location> <command> <command args>");
      System.exit(1);
    }
    
    String idxLocation = args[0];
    
    ClueApplication app = null;
    
    if (args.length > 1){
      String cmd = args[1];
      if ("readonly".equalsIgnoreCase(cmd)) {
        if (args.length > 2) {
          cmd = args[2];
          app = new ClueApplication(idxLocation, false);
          String[] cmdArgs;
          cmdArgs = new String[args.length - 3];
          System.arraycopy(args, 3, cmdArgs, 0, cmdArgs.length);
          app.ctx.setReadOnlyMode(true);
          app.handleCommand(cmd, cmdArgs, System.out);
        }
      }
      else {
        app = new ClueApplication(idxLocation, false);
        String[] cmdArgs;
        cmdArgs = new String[args.length - 2];
        System.arraycopy(args, 2, cmdArgs, 0, cmdArgs.length);
        app.handleCommand(cmd, cmdArgs, System.out);
      }
      return;
    }
    app = new ClueApplication(idxLocation, true);
    BufferedReader inReader = new BufferedReader(new InputStreamReader(System.in));
    while(true){
      System.out.print("> ");
      String line = inReader.readLine().trim();
      if (line.isEmpty()) continue;
      String[] parts = line.split("\\s");
      if (parts.length > 0){
        String cmd = parts[0];
        String[] cmdArgs = new String[parts.length - 1];
        System.arraycopy(parts, 1, cmdArgs, 0, cmdArgs.length);
        app.handleCommand(cmd, cmdArgs, System.out);
      }
    }
        
  }