diff --git a/build-tools/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchNode.java b/build-tools/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchNode.java index ff8930ed42c84..064f45de14f99 100644 --- a/build-tools/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchNode.java +++ b/build-tools/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchNode.java @@ -1216,10 +1216,15 @@ private void sync(Path sourceRoot, Path destinationRoot, BiConsumer syncMethod.accept(destination, source); } }); - } catch (NoSuchFileException e) { - // Ignore these files that are sometimes left behind by the JVM - if (e.getFile() == null || e.getFile().contains(".attach_pid") == false) { - throw new UncheckedIOException(e); + } catch (UncheckedIOException e) { + if (e.getCause() instanceof NoSuchFileException) { + NoSuchFileException cause = (NoSuchFileException) e.getCause(); + // Ignore these files that are sometimes left behind by the JVM + if (cause.getFile() == null || cause.getFile().contains(".attach_pid") == false) { + throw new UncheckedIOException(cause); + } + } else { + throw e; } } catch (IOException e) { throw new UncheckedIOException("Can't walk source " + sourceRoot, e);