-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix ErrorProne errors #3623
Fix ErrorProne errors #3623
Conversation
List<Path> allStyles = Files.find(jarFs.getRootDirectories().iterator().next(), 1, (file, attr) -> file.toString().endsWith("csl")).collect(Collectors.toList()); | ||
|
||
List<Path> allStyles; | ||
try (Stream<Path> stylefileStream = Files.find(jarFs.getRootDirectories().iterator().next(), 1, (file, attr) -> file.toString().endsWith("csl"))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is again one of the ugly cases where an unchecked exception could be thrown. Because streams and lambdas can't throw checked exceptions. In this case it could be that the stream is already closed when calling collect.
Similar to #3606
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, please catch IOUncheckedException
and rethrow it as IOException
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Except the stuff concerning unchecked IO exceptions, this looks good.
List<Path> allStyles = Files.find(jarFs.getRootDirectories().iterator().next(), 1, (file, attr) -> file.toString().endsWith("csl")).collect(Collectors.toList()); | ||
|
||
List<Path> allStyles; | ||
try (Stream<Path> stylefileStream = Files.find(jarFs.getRootDirectories().iterator().next(), 1, (file, attr) -> file.toString().endsWith("csl"))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, please catch IOUncheckedException
and rethrow it as IOException
.
@@ -331,8 +331,8 @@ public static String createDirNameFromPattern(BibDatabase database, BibEntry ent | |||
* @return the path to the first file that matches the defined conditions | |||
*/ | |||
public static Optional<Path> find(String filename, Path rootDirectory) { | |||
try { | |||
return Files.walk(rootDirectory) | |||
try (Stream<Path> pathStream = Files.walk(rootDirectory)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please check if walk
may also throw an IOUncheckedEx
and if yes, add it to the catch block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked the JavaDoc and the sources... does not seem so.
EDIT: it does :/
res.addAll(findFile(entry, subElement, restOfFileString, extensionRegExp)); | ||
} | ||
}); | ||
try (Stream<Path> pathStream = Files.walk(actualDirectory)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here also
} | ||
|
||
private List<Path> collectMatchingFiles(Path actualDirectory, BiPredicate<Path, BasicFileAttributes> matcher) { | ||
try (Stream<Path> pathStream = Files.find(actualDirectory, 1, matcher)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here
@tobiasdiez @Siedlerchr Can you have a look if the exception handling is correct now? see c93ae63 for that |
try (Stream<Path> pathStream = Files.find(actualDirectory, 1, matcher)) { | ||
return pathStream.collect(Collectors.toList()); | ||
} catch (UncheckedIOException | IOException ioe) { | ||
return Collections.emptyList(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this method should just rethrow as IOException.
@LinusDietz Thanks, the code looks good to me! |
This fixes