Skip to content
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

Merged
merged 20 commits into from
Jan 10, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Optional;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
Expand Down Expand Up @@ -153,8 +154,10 @@ public static List<CitationStyle> discoverCitationStyles() {

try (FileSystem jarFs = FileSystems.newFileSystem(Paths.get(path), null)) {

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"))) {
Copy link
Member

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

Copy link
Member

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.

allStyles = stylefileStream.collect(Collectors.toList());
}
for (Path style : allStyles) {
CitationStyle.createCitationStyleFromFile(style.getFileName().toString())
.ifPresent(STYLES::add);
Expand Down