8166164: compiler/compilercontrol/share/processors/LogProcessor.java does not close Scanner
authoriignatyev
Tue, 20 Sep 2016 17:30:33 +0300
changeset 41329 f79b4f079360
parent 41328 2bea535779f6
child 41330 8b2580e63aa0
8166164: compiler/compilercontrol/share/processors/LogProcessor.java does not close Scanner Reviewed-by: kvn, ppunegov
hotspot/test/compiler/compilercontrol/share/processors/LogProcessor.java
--- a/hotspot/test/compiler/compilercontrol/share/processors/LogProcessor.java	Mon Sep 19 13:26:37 2016 -0700
+++ b/hotspot/test/compiler/compilercontrol/share/processors/LogProcessor.java	Tue Sep 20 17:30:33 2016 +0300
@@ -74,7 +74,7 @@
         if (loggedMethods.isEmpty()) {
             return;
         }
-        matchTasks(getScanner());
+        matchTasks();
     }
 
     /*
@@ -95,19 +95,21 @@
      * Parses for <task method='java.lang.String indexOf (I)I' >
      * and finds if there is a compilation log for this task
      */
-    private void matchTasks(Scanner scanner) {
-        String task = scanner.findWithinHorizon(TASK_ELEMENT, 0);
-        while (task != null) {
-            String element = scanner.findWithinHorizon(ANY_ELEMENT, 0);
-            if (Pattern.matches(TASK_DONE_ELEMENT, element)
-                    || Pattern.matches(TASK_END_ELEMENT, element)) {
-                /* If there is nothing between <task> and </task>
-                   except <task done /> then compilation log is empty.
-                   Check the method in this task should not be logged */
-                Asserts.assertFalse(matchMethod(task), "Compilation log "
-                        + "expected. Met: " + element);
-            }
-            task = scanner.findWithinHorizon(TASK_ELEMENT, 0);
+    private void matchTasks() {
+        try (Scanner scanner = getScanner()) {
+          String task = scanner.findWithinHorizon(TASK_ELEMENT, 0);
+          while (task != null) {
+              String element = scanner.findWithinHorizon(ANY_ELEMENT, 0);
+              if (Pattern.matches(TASK_DONE_ELEMENT, element)
+                      || Pattern.matches(TASK_END_ELEMENT, element)) {
+                  /* If there is nothing between <task> and </task>
+                     except <task done /> then compilation log is empty.
+                     Check the method in this task should not be logged */
+                  Asserts.assertFalse(matchMethod(task), "Compilation log "
+                          + "expected. Met: " + element);
+              }
+              task = scanner.findWithinHorizon(TASK_ELEMENT, 0);
+          }
         }
     }