# HG changeset patch # User iignatyev # Date 1473972630 -10800 # Thu Sep 15 23:50:30 2016 +0300 # Node ID b10bce631b1e9c7a1387033427cb463cdf9b84c4 # Parent 2429e047ae9b8d01226cb3611b6f56e895cc11d6 8166164: compiler/compilercontrol/share/processors/LogProcessor.java does not close Scanner Reviewed-by: duke diff --git a/test/compiler/compilercontrol/share/processors/LogProcessor.java b/test/compiler/compilercontrol/share/processors/LogProcessor.java --- a/test/compiler/compilercontrol/share/processors/LogProcessor.java +++ b/test/compiler/compilercontrol/share/processors/LogProcessor.java @@ -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 and - except 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 and + except 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); + } } }