#vulnerable code 
                              @Test
  public void testRerun() {
    final SqlLine beeLine = new SqlLine();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    final File tmpHistoryFile = createTempFile("tmpHistory", "temp");
    try (BufferedWriter bw =
             new BufferedWriter(
                 new OutputStreamWriter(
                     new FileOutputStream(tmpHistoryFile),
                     StandardCharsets.UTF_8))) {
      bw.write("1536743099591:SELECT \\n CURRENT_TIMESTAMP \\n as \\n c1;\n"
          + "1536743104551:!/ 4\n"
          + "1536743104551:!/ 5\n"
          + "1536743104551:!/ 2\n"
          + "1536743104551:!/ 7\n"
          + "1536743107526:!history\n"
          + "1536743115431:!/ 3\n"
          + "1536743115431:!/ 8\n");
      bw.flush();

      SqlLine.Status status = begin(beeLine, os, true,
          "--historyfile=" + tmpHistoryFile.getAbsolutePath(),
          "-e", "!set maxwidth 80");
      assertThat(status, equalTo(SqlLine.Status.OK));
      DispatchCallback dc = new DispatchCallback();
      beeLine.runCommands(dc,
          "!set incremental true",
          "!set maxcolumnwidth 30",
          "!connect "
              + ConnectionSpec.H2.url + " "
              + ConnectionSpec.H2.username + " "
              + "\"\"");
      os.reset();

      beeLine.runCommands(dc, "!/ 1");
      String output = os.toString("UTF8");
      final String expected0 = "+----------------------------+";
      final String expected1 = "|             C1             |";
      final String expected2 = "1 row selected";
      assertThat(output,
          allOf(containsString(expected0),
              containsString(expected1),
              containsString(expected2)));
      os.reset();

      beeLine.runCommands(dc, "!/ 4");
      output = os.toString("UTF8");
      String expectedLine3 = "Cycled rerun of commands from history [2, 4]";
      assertThat(output, containsString(expectedLine3));
      os.reset();

      beeLine.runCommands(dc, "!/ 3");
      output = os.toString("UTF8");
      String expectedLine4 = "Cycled rerun of commands from history [3, 5, 7]";
      assertThat(output, containsString(expectedLine4));
      os.reset();

      beeLine.runCommands(dc, "!/ 8");
      output = os.toString("UTF8");
      String expectedLine5 = "Cycled rerun of commands from history [8]";
      assertThat(output, containsString(expectedLine5));
      os.reset();

      beeLine.runCommands(dc, "!rerun " + Integer.MAX_VALUE);
      output = os.toString("UTF8");
      String expectedLine6 =
          "Usage: rerun <offset>, available range of offset is -7..8";
      assertThat(output, containsString(expectedLine6));
      beeLine.runCommands(new DispatchCallback(), "!quit");
      assertTrue(beeLine.isExit());
    } catch (Exception e) {
      // fail
      throw new RuntimeException(e);
    }
  } 
                            #location 71 
                            #vulnerability type RESOURCE_LEAK
#fixed code
                              @Test
  public void testRerun() {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    final File tmpHistoryFile = createTempFile("tmpHistory", "temp");
    try (BufferedWriter bw =
             new BufferedWriter(
                 new OutputStreamWriter(
                     new FileOutputStream(tmpHistoryFile),
                     StandardCharsets.UTF_8))) {
      bw.write("1536743099591:SELECT \\n CURRENT_TIMESTAMP \\n as \\n c1;\n"
          + "1536743104551:!/ 4\n"
          + "1536743104551:!/ 5\n"
          + "1536743104551:!/ 2\n"
          + "1536743104551:!/ 7\n"
          + "1536743107526:!history\n"
          + "1536743115431:!/ 3\n"
          + "1536743115431:!/ 8\n");
      bw.flush();

      SqlLine.Status status = begin(sqlLine, os, true,
          "--historyfile=" + tmpHistoryFile.getAbsolutePath(),
          "-e", "!set maxwidth 80");
      assertThat(status, equalTo(SqlLine.Status.OK));
      DispatchCallback dc = new DispatchCallback();
      sqlLine.runCommands(dc,
          "!set incremental true",
          "!set maxcolumnwidth 30",
          "!connect "
              + ConnectionSpec.H2.url + " "
              + ConnectionSpec.H2.username + " "
              + "\"\"");
      os.reset();

      sqlLine.runCommands(dc, "!/ 1");
      String output = os.toString("UTF8");
      final String expected0 = "+----------------------------+";
      final String expected1 = "|             C1             |";
      final String expected2 = "1 row selected";
      assertThat(output,
          allOf(containsString(expected0),
              containsString(expected1),
              containsString(expected2)));
      os.reset();

      sqlLine.runCommands(dc, "!/ 4");
      output = os.toString("UTF8");
      String expectedLine3 = "Cycled rerun of commands from history [2, 4]";
      assertThat(output, containsString(expectedLine3));
      os.reset();

      sqlLine.runCommands(dc, "!/ 3");
      output = os.toString("UTF8");
      String expectedLine4 = "Cycled rerun of commands from history [3, 5, 7]";
      assertThat(output, containsString(expectedLine4));
      os.reset();

      sqlLine.runCommands(dc, "!/ 8");
      output = os.toString("UTF8");
      String expectedLine5 = "Cycled rerun of commands from history [8]";
      assertThat(output, containsString(expectedLine5));
      os.reset();

      sqlLine.runCommands(dc, "!rerun " + Integer.MAX_VALUE);
      output = os.toString("UTF8");
      String expectedLine6 =
          "Usage: rerun <offset>, available range of offset is -7..8";
      assertThat(output, containsString(expectedLine6));
      sqlLine.runCommands(new DispatchCallback(), "!quit");
      assertTrue(sqlLine.isExit());
    } catch (Exception e) {
      // fail
      throw new RuntimeException(e);
    }
  }