Skip to content

Commit

Permalink
fix: Fix the critical SonarQube failures: close the Scanner after usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-weirdo committed Nov 6, 2024
1 parent 37660cc commit cb349f3
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,16 @@ private static String loadUrlToString(final String urlString) throws IOException

// todo: use some nice library instead
URL url = new URL(urlString);
String out = new Scanner(url.openStream(), StandardCharsets.UTF_8) // this line will require java 10
.useDelimiter("\\A")
.next();

logger.debug("Response for url {}:", urlString);
logger.debug(StringUtils.abbreviate(out, 100)); // do not spam the whole response to log!
return out;
try (Scanner scanner = new Scanner(url.openStream(), StandardCharsets.UTF_8)) {
String out = scanner // this line will require java 10
.useDelimiter("\\A")
.next();

logger.debug("Response for url {}:", urlString);
logger.debug(StringUtils.abbreviate(out, 100)); // do not spam the whole response to log!
return out;
}
}

static List<ImmutablePair<Integer, Integer>> split(Config config) {
Expand Down

0 comments on commit cb349f3

Please sign in to comment.