Skip to content

Commit

Permalink
Make code more readable.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Sep 15, 2023
1 parent 70bece6 commit 1778685
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/main/java/io/jenkins/plugins/fontawesome/FontAwesomeIcons.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,12 @@ private static Map<String, String> getIconsFromClasspath(@CheckForNull final Fon
}

@SuppressFBWarnings("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE")
private static Map<String, String> collectIcons(final Path path, @CheckForNull final FontAwesomeStyle filter)
throws IOException {
private static Map<String, String> collectIcons(
@CheckForNull final Path path, @CheckForNull final FontAwesomeStyle filter) throws IOException {
Map<String, String> icons = new LinkedHashMap<>();

if (path != null) {
try (Stream<Path> stream = filter == null ? Files.walk(path, 2) : Files.walk(
path.resolve(filter.name().toLowerCase(Locale.ENGLISH)), 1)) {
try (Stream<Path> stream = findIcons(path, filter)) {
stream.filter(icon -> icon != null && icon.getFileName() != null && StringUtils.endsWith(

Check warning on line 109 in src/main/java/io/jenkins/plugins/fontawesome/FontAwesomeIcons.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 109 is only partially covered, 2 branches are missing
icon.getFileName().toString(), SVG_FILE_ENDING))

Check warning on line 110 in src/main/java/io/jenkins/plugins/fontawesome/FontAwesomeIcons.java

View check run for this annotation

ci.jenkins.io / SpotBugs

NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE

LOW: Possible null pointer dereference in io.jenkins.plugins.fontawesome.FontAwesomeIcons.lambda$collectIcons$0(Path) due to return value of called method
Raw output
<p> The return value from a method is dereferenced without a null check, and the return value of that method is one that should generally be checked for null. This may lead to a <code>NullPointerException</code> when the code is executed. </p>
.sorted().forEach(icon -> {
Expand All @@ -124,6 +123,14 @@ private static Map<String, String> collectIcons(final Path path, @CheckForNull f
return icons;
}

private static Stream<Path> findIcons(final Path path, @CheckForNull final FontAwesomeStyle filter) throws IOException {
if (filter == null) {
return Files.walk(path, 2);
}

return Files.walk(path.resolve(filter.name().toLowerCase(Locale.ENGLISH)), 1);
}

private FontAwesomeIcons() {
// hidden
}
Expand Down

0 comments on commit 1778685

Please sign in to comment.