Skip to content

Comments

Fix FTP/SFTP listener not triggering when fileNamePattern is not specified#1548

Merged
niveathika merged 2 commits intomasterfrom
fix-optional-filenamepattern
Feb 16, 2026
Merged

Fix FTP/SFTP listener not triggering when fileNamePattern is not specified#1548
niveathika merged 2 commits intomasterfrom
fix-optional-filenamepattern

Conversation

@niveathika
Copy link
Contributor

@niveathika niveathika commented Feb 13, 2026

Summary

  • Fix FTP/SFTP listener not triggering when fileNamePattern configuration is not specified

Root Cause

When no fileNamePattern was provided, the listener would not trigger for any files because:

Empty string default: When fileNamePattern was not specified, it defaulted to an empty string "". Since "filename".matches("") returns false for any non-empty filename in Java, all files were filtered out.

Fix

  • Only add fileNamePattern to params if it's non-null and non-empty (making it truly optional)
  • When absent, RemoteFileSystemConsumer.fileNamePattern remains null, and the filter correctly allows all files through

Fixes wso2/product-ballerina-integrator#656

Test plan

  • Test FTP/SFTP listener without specifying fileNamePattern - should trigger for all files
  • Test FTP/SFTP listener with fileNamePattern specified - should only trigger for matching files/directories

🤖 Generated with Claude Code

Summary

This PR fixes an issue where FTP/SFTP listeners did not trigger when the optional fileNamePattern configuration was omitted. The change ensures listeners behave correctly both when a pattern is absent and when a pattern is specified.

Changes Made

  • FtpListenerHelper.java: Only set the FILE_NAME_PATTERN parameter when a non-empty value is provided; omit it when absent so the consumer receives a null pattern instead of an empty string.
  • RemoteFileSystemConsumer.java: Apply the filename pattern filter only when a pattern is present; preserve directory traversal so files nested in non-matching directories are still discovered. Logging for filtered files was improved to include the file URI and pattern.
  • changelog.md: Added an unreleased entry documenting the fix.

Outcome

  • Listeners without fileNamePattern now trigger for all files in the watched directory.
  • Listeners with fileNamePattern continue to trigger only for files matching the specified pattern.
  • Files nested within directories are correctly detected regardless of parent directory names.

@coderabbitai
Copy link

coderabbitai bot commented Feb 13, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Fixes FTP/SFTP listener behavior so fileNamePattern is only validated/used when explicitly provided; pattern assignment is skipped when empty, and directory filtering applies only when a pattern is set.

Changes

Cohort / File(s) Summary
Changelog
changelog.md
Added unreleased entry: "Fix FTP/SFTP listener not triggering when fileNamePattern is not specified".
Endpoint config / validation
native/src/main/java/io/ballerina/stdlib/ftp/server/FtpListenerHelper.java
addStringProperty now skips computing/validating/setting FILE_NAME_PATTERN when ENDPOINT_CONFIG_FILE_PATTERN is missing or empty.
Directory handling & logging
native/src/main/java/io/ballerina/stdlib/ftp/transport/server/RemoteFileSystemConsumer.java
handleDirectory now filters files only if fileNamePattern is non-null; renamed logging helper to logDebugFileNamePatternNotMatched(FileObject) and improved log to include file URI and pattern.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested reviewers

  • shafreenAnfar
  • DimuthuMadushan
  • ThisaruGuruge
  • MohamedSabthar

Poem

🐰 I hopped through folders, soft and fleet,
No pattern found — no missed heartbeat,
Now only when patterns come to play,
Do I pause and look the files away.
✨ Hooray — listeners wake and greet!

🚥 Pre-merge checks | ✅ 4 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Merge Conflict Detection ⚠️ Warning ❌ Merge conflicts detected (3 files):

⚔️ changelog.md (content)
⚔️ native/src/main/java/io/ballerina/stdlib/ftp/server/FtpListenerHelper.java (content)
⚔️ native/src/main/java/io/ballerina/stdlib/ftp/transport/server/RemoteFileSystemConsumer.java (content)

These conflicts must be resolved before merging into master.
Resolve conflicts locally and push changes to this branch.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: fixing FTP/SFTP listener triggering when fileNamePattern is not specified.
Description check ✅ Passed The description includes summary, root cause analysis, fix explanation, linked issue reference, and test plan items. However, the template checklist items are not explicitly checked off, and the spec/native-image compatibility sections are not addressed.
Linked Issues check ✅ Passed The PR correctly addresses issue #656 by fixing the root cause where fileNamePattern defaulting to empty string filtered out all files. The implementation ensures fileNamePattern remains null when absent, allowing the filter to pass all files through.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the fileNamePattern bug: FtpListenerHelper only adds pattern if non-empty, RemoteFileSystemConsumer filtering logic updated to handle null pattern correctly, and changelog entry added. No unrelated changes detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-optional-filenamepattern
⚔️ Resolve merge conflicts (beta)
  • Auto-commit resolved conflicts to branch fix-optional-filenamepattern
  • Create stacked PR with resolved conflicts
  • Post resolved changes as copyable diffs in a comment

No actionable comments were generated in the recent review. 🎉


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In
`@native/src/main/java/io/ballerina/stdlib/ftp/transport/server/RemoteFileSystemConsumer.java`:
- Around line 265-278: The recursive directory traversal in
RemoteFileSystemConsumer leaves intermediate FileObject instances open; after
obtaining childFileObject = child.getChildren() and after recursion via
handleDirectory(childFileObject), ensure you call child.close() in a finally
block (or use a safeClose helper) to release the intermediate directory
resource, and also explicitly close each FileObject contained in childFileObject
after processing them (or have handleDirectory close its entries) to avoid
leaking remote filesystem handles; update the code around child.getChildren(),
handleDirectory(...) and closeDirectories() to perform these explicit closes
(use FileObject.close()/closeQuietly as appropriate).

…ified

When no fileNamePattern was provided, the listener would not trigger
for any files. This was caused by:

Empty string default: When fileNamePattern was not specified, it
defaulted to an empty string "". Since `"filename".matches("")`
returns false for any non-empty filename, all files were filtered out.

Fix:
- Only add fileNamePattern to params if it's non-null and non-empty.
  When absent, RemoteFileSystemConsumer.fileNamePattern remains null,
  and the filter correctly allows all files through.

Fixes wso2/product-ballerina-integrator#656
@niveathika niveathika force-pushed the fix-optional-filenamepattern branch from 2521c30 to e4c1328 Compare February 14, 2026 16:54
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
changelog.md (1)

2-2: ⚠️ Potential issue | 🟡 Minor

Pre-existing documentation error: Incorrect package name.

Line 2 references "Ballerina Email package" but this changelog documents changes to the Ballerina FTP package. This is a pre-existing error that should be corrected for accuracy.

📝 Proposed fix
-This file contains all the notable changes done to the Ballerina Email package through the releases.
+This file contains all the notable changes done to the Ballerina FTP package through the releases.

@codecov
Copy link

codecov bot commented Feb 14, 2026

Codecov Report

❌ Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 76.61%. Comparing base (883221b) to head (c001ac3).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
...ballerina/stdlib/ftp/server/FtpListenerHelper.java 75.00% 0 Missing and 1 partial ⚠️

❌ Your project status has failed because the head coverage (76.61%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1548      +/-   ##
============================================
+ Coverage     75.76%   76.61%   +0.84%     
- Complexity      822     1043     +221     
============================================
  Files            60       76      +16     
  Lines          4168     4823     +655     
  Branches        701      837     +136     
============================================
+ Hits           3158     3695     +537     
- Misses          703      756      +53     
- Partials        307      372      +65     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sonarqubecloud
Copy link

@niveathika niveathika merged commit bdad6c2 into master Feb 16, 2026
10 of 15 checks passed
@niveathika niveathika deleted the fix-optional-filenamepattern branch February 16, 2026 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SFTP service is not triggered on file changes

2 participants