Salvatore Mongiardo created CAMEL-26639:
-------------------------------------------

             Summary: camel-file silently fails to poll files on Windows when 
URI uses absolute path with backslashes
                 Key: CAMEL-26639
                 URL: https://issues.apache.org/jira/browse/CAMEL-26639
             Project: Camel
          Issue Type: Bug
          Components: camel-file
            Reporter: Salvatore Mongiardo


h2. Summary

On Windows, when a Camel file: URI contains an absolute path with backslashes 
(e.g. {{file:C:\\Users\\...\\target}}), the file consumer starts successfully 
but never polls any files. No exceptions are logged, no files are processed - 
completely silent failure.

h2. Root Cause

When {{Paths.get("target").toAbsolutePath().toString()}} is used on Windows, it 
returns a path with backslashes (e.g. {{C:\\Users\\...\\target}}). When this is 
interpolated into a Camel {{file:}} URI:

# {{UnsafeUriCharactersEncoder.encode()}} encodes backslash as %5C
# {{URI.getSchemeSpecificPart()}} decodes it back
# The route internal URI representation retains the encoded form
# The file consumer display name shows {{file://C:%5CUsers%5C...}}
# The file poller silently fails to detect files in the directory

On Linux/macOS this never happens because toAbsolutePath() always uses forward 
slashes.

h2. Steps to Reproduce

{code:java}
String directory = Paths.get("target").toAbsolutePath().toString();
// On Windows: C:\Users\test\target

fromF("file:%s?fileName=%s", directory, "test.txt")
    .to("log:result");
{code}

The route starts and logs:
{code}
Started route1 (file://C:%5CUsers%5Ctest%5Ctarget)
{code}

But no files are ever polled.

h2. Expected Behavior

The file consumer should normalize backslashes to forward slashes and poll the 
directory correctly.

h2. Proposed Fix

Normalize backslashes to forward slashes in 
{{FileComponent.buildFileEndpoint()}} before creating the File object:

{code:java}
remaining = remaining.replace('\\', '/');
{code}

This is safe because Java File class handles forward slashes on all platforms.

h2. Environment

* Windows Server 2019/2025
* JDK 21
* Camel 4.22.x (also affects main)



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to