diff options
| author | 2026-08-24 09:50:26 +0200 | |
|---|---|---|
| committer | 2026-08-24 09:50:26 +0200 | |
| commit | 5eb086260022242a736e9e44deebd973b07e540d (patch) | |
| tree | 463258033df1bb9bca6981c8082d1bf6fea8ca3c /src/main/java/com/it_jaros | |
| parent | 1486609f8f67ca1103989302fd60e4741458b152 (diff) | |
Simplified code and refactored method to check also current Throwable
and also causes
Diffstat (limited to 'src/main/java/com/it_jaros')
| -rw-r--r-- | src/main/java/com/it_jaros/jns/scan/Scanner.java | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/src/main/java/com/it_jaros/jns/scan/Scanner.java b/src/main/java/com/it_jaros/jns/scan/Scanner.java index 9e84c80..c388ef3 100644 --- a/src/main/java/com/it_jaros/jns/scan/Scanner.java +++ b/src/main/java/com/it_jaros/jns/scan/Scanner.java @@ -61,7 +61,7 @@ public class Scanner implements AutoCloseable { } private Optional<ScanResult> mapToScanResult(Throwable error) { - if (error instanceof RejectedExecutionException) { + if (isCauseChainInstanceOf(error, RejectedExecutionException.class, InterruptedException.class)) { // happens when Ctrl-C is pressed // we don't want to tell the user that // the host had an error because it did @@ -71,11 +71,6 @@ public class Scanner implements AutoCloseable { } if (error instanceof ScanHostException e) { - if (isCauseChainInstanceOf(e, RejectedExecutionException.class, InterruptedException.class)) { - // see comment above - return Optional.empty(); - } - return Optional.of(ScanResult.from(e)); } @@ -83,18 +78,17 @@ public class Scanner implements AutoCloseable { } private boolean isCauseChainInstanceOf(Throwable e, Class<?> ...classesToCheckFor) { - Throwable causeToCheckFor = e.getCause(); - if (causeToCheckFor == null) { + if (e == null) { return false; } for (Class<?> clazz : classesToCheckFor) { - if (clazz.isInstance(causeToCheckFor)) { + if (clazz.isInstance(e)) { return true; } } - return isCauseChainInstanceOf(causeToCheckFor, classesToCheckFor); + return isCauseChainInstanceOf(e.getCause(), classesToCheckFor); } public boolean awaitTermination(Duration duration) throws InterruptedException { |
