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

Catch and propagate UncheckedIOException in FileFinder #3603

Merged
merged 6 commits into from
Jan 9, 2018

Conversation

tobiasdiez
Copy link
Member

@tobiasdiez tobiasdiez commented Jan 4, 2018

Catch UncheckedIOException and converted it to a usual IOException. Similarly for an PatternSyntaxException. These are ones of the rare exceptions that were never handled but are reported in azure.


  • Change in CHANGELOG.md described (not worth it)
  • Tests created for changes
  • Screenshots added (for bigger UI changes)
  • Manually tested changed features in running JabRef
  • Check documentation status (Issue created for outdated help page at help.jabref.org?)
  • If you changed the localization: Did you run gradle localizationUpdate?

@tobiasdiez tobiasdiez added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Jan 4, 2018
@@ -93,8 +94,8 @@ private boolean matches(String filename, String citeKey) {
if (Files.exists(directory)) {
try (Stream<Path> files = Files.find(directory, Integer.MAX_VALUE, isFileWithCorrectExtension)) {
result.addAll(files.collect(Collectors.toSet()));
} catch (IOException e) {
LOGGER.error("Problem in finding files", e);
} catch (UncheckedIOException e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's interesting, why/when does this Exception occur?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I have no idea. The documentation babbles something about "a late exception that is thrown when the stream is finished". I guess the file is found, added to the stream but when a bit later toSet is called it is no longer there. I also don't understand why it has to be an unchecked exception instead of a normal IOException.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored the code slightly to get rid of these exception handling in streams.
I think this is should work better now because the stream is no longer directly closed and then accessed. But I could be mistaken.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that works (see below). But thanks for the other fix, that's a nice improvement over my hacky code.

} catch (UncheckedIOException e) {
throw new IOException("Problem in finding files", e);
}
result.addAll(Files.find(directory, Integer.MAX_VALUE, isFileWithCorrectExtension).collect(Collectors.toSet()));
Copy link
Member Author

@tobiasdiez tobiasdiez Jan 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please explain this change and why you removed the try-catch as the point of this PR was to actually catch this UncheckedIOException. Since Files.find still returns a stream, this exception can still occur, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your code did not compile, you can't throw an exception inside a lambda/stream. That's impossible.
I did not realize that the unchecked exception can still occur. But we should just log it. I mean, what else can we do about it?`We can't rethrow it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just pushed a new solution. I think this kind of catch-rethrow should work.

Copy link
Member

@Siedlerchr Siedlerchr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that could work now

@tobiasdiez
Copy link
Member Author

I merge this now so that it can serve as the base for #3623.

@tobiasdiez tobiasdiez merged commit 2d10f83 into master Jan 9, 2018
@tobiasdiez tobiasdiez deleted the fixUncatchedIOExcep branch January 9, 2018 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants