Skip to content

Commit

Permalink
test: Ensure file is closed after reading lines (#12990) (#13035)
Browse files Browse the repository at this point in the history
Used a try-with-resources statement to ensure that log file gets closed
after iterating over its contents.

Co-authored-by: Marco Collovati <[email protected]>
  • Loading branch information
vaadin-bot and mcollovati authored Feb 16, 2022
1 parent 4e7bbb4 commit fd33877
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;

import org.junit.Assert;
import org.junit.Test;
Expand Down Expand Up @@ -70,8 +71,8 @@ private int measureLogEntryTimeDistance(String startFragment,
Pattern endPattern = createPattern(endFragment);
AtomicInteger startTime = new AtomicInteger();
AtomicInteger endTime = new AtomicInteger();
try {
Files.lines(getLogPath()).forEach(line -> {
try (Stream<String> lines = Files.lines(getLogPath())) {
lines.forEach(line -> {
Matcher matcherFirst = startPattern.matcher(line);
if (matcherFirst.matches() && startTime.get() == 0) {
startTime.set(Integer.parseInt(matcherFirst.group(1)));
Expand Down

0 comments on commit fd33877

Please sign in to comment.