gnodet-bot commented on code in PR #27847:
URL: https://github.com/apache/camel/pull/27847#discussion_r4275522802


##########
core/camel-support/src/main/java/org/apache/camel/support/RouteWatcherReloadStrategy.java:
##########
@@ -193,6 +230,127 @@ protected void doStart() throws Exception {
         super.doStart();
     }
 
+    private static boolean matches(AntPathMatcher matcher, String part, String 
name, String path, String relative) {
+        return name.equals(part) || matcher.match(part, path, false)
+                || relative != null && matcher.match(part, relative, false);
+    }
+
+    /**
+     * A folder that an exclude of the pattern matches as a whole, such as 
<tt>inbox</tt> for <tt>!inbox/**</tt>: the
+     * folder is left out of the scan, so the files the routes read and write 
in it are not walked on every scan.
+     */
+    @Override
+    protected boolean isExcludedDirectory(Path dir) {
+        if (excludes.isEmpty() || folder == null) {
+            return false;
+        }
+        String relative = relativePath(dir.toFile());
+        if (relative == null || relative.isEmpty()) {
+            return false;
+        }
+        for (String part : excludes) {
+            // inbox and inbox/** match the folder itself; a file pattern such 
as *.json does not leave a folder out
+            if (part.equals(relative) || AntPathMatcher.INSTANCE.match(part, 
relative + "/_", false)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /** The file a route was loaded from, as an absolute path, or null when it 
is not a file. */
+    private static Path sourcePath(Resource resource) {
+        String location = resource != null ? resource.getLocation() : null;
+        if (location == null || location.contains(":") && 
!location.startsWith("file:")) {
+            return null;
+        }
+        try {
+            return Paths.get(location.startsWith("file:") ? 
location.substring(5) : location).toAbsolutePath().normalize();
+        } catch (Exception e) {

Review Comment:
   💡 **Overly broad catch** — `Paths.get()` only throws `InvalidPathException` 
(a subtype of `IllegalArgumentException`). Catching `Exception` here silently 
swallows anything unexpected (e.g. a `SecurityException` from the security 
manager). Narrowing it is straightforward and makes the failure mode explicit:
   
   ```suggestion
           try {
               return Paths.get(location.startsWith("file:") ? 
location.substring(5) : location).toAbsolutePath().normalize();
           } catch (InvalidPathException e) {
               return null;
           }
   ```
   
   If the intent is "any path resolution failure → treat as non-file source", 
that's fine, but `InvalidPathException` is the only checked failure mode here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to