Skip to content

Commit

Permalink
Fix for cryptomator#2989 - improved code readability and exception
Browse files Browse the repository at this point in the history
- better use of the Optional class
- throws IllegalArgumentException is more appropriate when a required object is not present
  • Loading branch information
odouglsantos committed Jul 11, 2023
1 parent 4e61593 commit a15f8eb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
4 changes: 1 addition & 3 deletions src/main/java/org/cryptomator/ui/error/ErrorController.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@ private void loadHttpResponse(HttpResponse<InputStream> response) {
.thenComparing(this::compareIsAnswered)//
.thenComparing(this::compareUpvoteCount));

if (value.isPresent()) {
matchingErrorDiscussion.set(value.get());
}
value.ifPresent(matchingErrorDiscussion::set);
}
} catch (IOException e) {
LOG.error("Failed to load or parse JSON from " + response.uri(), e);
Expand Down
12 changes: 2 additions & 10 deletions src/main/java/org/cryptomator/ui/fxapp/UpdateCheckerModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,8 @@ static ScheduledService<String> provideCheckForUpdatesService(ExecutorService ex
ScheduledService<String> service = new ScheduledService<>() {
@Override
protected Task<String> createTask() {
if (httpClient.isPresent()) {
return new UpdateCheckerTask(httpClient.get(), checkForUpdatesRequest);
} else {
return new Task<>() {
@Override
protected String call() {
throw new NullPointerException("No HttpClient present.");
}
};
}
return httpClient.map(client -> new UpdateCheckerTask(client, checkForUpdatesRequest))
.orElseThrow(() -> new IllegalArgumentException("No HttpClient present."));
}
};
service.setOnFailed(event -> LOG.error("Failed to execute update service", service.getException()));
Expand Down

0 comments on commit a15f8eb

Please sign in to comment.