From e39ec6cab4c153d1c7e9fe03a956b0937975fc65 Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Wed, 2 Dec 2020 08:02:09 +0100 Subject: [PATCH] Issue #5086 Fix error on addFile Signed-off-by: Jan Bartel --- .../java/org/eclipse/jetty/util/Scanner.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/Scanner.java b/jetty-util/src/main/java/org/eclipse/jetty/util/Scanner.java index c322ecc1589c..70fd1fc78276 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/Scanner.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/Scanner.java @@ -349,11 +349,16 @@ public void addFile(Path p) if (p == null) throw new IllegalStateException("Null path"); - File f = p.toFile(); - if (!f.exists() || f.isDirectory()) + if (!Files.exists(p) || Files.isDirectory(p)) throw new IllegalStateException("Not file or doesn't exist: " + p); - - _scannables.putIfAbsent(p, null); + try + { + _scannables.putIfAbsent(p.toRealPath(), new IncludeExcludeSet<>(PathMatcherSet.class)); + } + catch (IOException e) + { + throw new IllegalStateException(e); + } } /** @@ -370,15 +375,13 @@ public IncludeExcludeSet addDirectory(Path p) if (p == null) throw new IllegalStateException("Null path"); - File f = p.toFile(); - if (!f.exists() || !f.isDirectory()) + if (!Files.exists(p) || !Files.isDirectory(p)) throw new IllegalStateException("Not directory or doesn't exist: " + p); try { - Path real = p.toRealPath(); IncludeExcludeSet includesExcludes = new IncludeExcludeSet<>(PathMatcherSet.class); - IncludeExcludeSet prev = _scannables.putIfAbsent(real, includesExcludes); + IncludeExcludeSet prev = _scannables.putIfAbsent(p.toRealPath(), includesExcludes); if (prev != null) includesExcludes = prev; return includesExcludes;