Fix file:write CREATE_NEW temp-file path resolution on Windows [Issue #5016] - #297
Merged
ravindu25 merged 3 commits intoJun 2, 2026
Conversation
Replace manual string concatenation of `parent.getName().getPath() + "/" + basename + ".tmp"` with `targetFile.getParent().resolveFile(basename + ".tmp")` in WriteFile.java's CREATE_NEW branch. The old code stripped the URI scheme and Windows drive letter from the path (VFS FileName.getPath() returns only the path component relative to the rootFile), causing DefaultFileSystemManager to throw "Could not find file with URI ... because it is a relative path, and no base URI was provided" on Windows hosts. The fix restores the v4.0.28 parent-relative resolve idiom so the temp file URI preserves the scheme and drive letter on Windows, Linux, and UNC paths. Add WriteFileTempFileResolutionTest (TestNG) with 10 tests covering Windows, Linux, UNC, smb2, reserved-char encoding, drive-root edge case, and end-to-end createFile/write/moveTo. Fixes: wso2/product-integrator-mi#4907
ravindu25
force-pushed
the
fix/issue-5016-windows-write-create-new
branch
from
May 28, 2026 06:25
2393a43 to
654d834
Compare
GDLMadushanka
approved these changes
May 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
file:writeinCREATE_NEWmode fails 100% of the time on Windows withFileSystemException: Could not find file with URI "/wso2/mi/LocalEntry/out/fileName.csv.tmp" because it is a relative path, and no base URI was provided.Root Cause
In
WriteFile.javalines 448–449 (CREATE_NEWbranch), the temp file was constructed by string-concatenatingtargetFile.getParent().getName().getPath() + "/" + basename + ".tmp"and passing that string tofileSystemHandlerConnection.resolveFileWithSuspension(String).FileName.getPath()in Commons VFS intentionally returns only the path component relative to the rootFile — on Windows, the drive letter (C:) is part of the rootFile and is not included ingetPath(). The concatenated string therefore has no URI scheme and no drive letter (e.g./wso2/mi/LocalEntry/out/fileName.csv.tmp), which matches the URI in the customer's stack trace exactly.DefaultFileSystemManager.resolveFile(String)cannot find a provider for a scheme-less string with no drive letter and throws the documented exception.The same string-concatenation pattern accidentally "works" on Linux because the resulting bare absolute path under
/happens to look valid to VFS — but it silently resolves to the wrong filesystem location (a latent data-loss bug).Fix
Replace the manual string concatenation with the standard VFS parent-relative resolve idiom:
FileObject.resolveFile(String)resolves the child name against the parentFileObject, which already carries the scheme and rootFile (drive letter or UNC share). This restores the behavior of v4.0.28 (fsManager.resolveFile(parent, basename + ".tmp")), which worked correctly on Windows.No new imports. No other lines changed. The body of the
try-with-resources block (tempFile.createFile(),performContentWrite/performBodyWrite,tempFile.moveTo(targetFile)) is untouched.Verification
Verified at library level against the exact
commons-vfs2_2.2.0.wso2v20_3.jarshipped inwso2mi-4.4.0.30.zip:file:///C:/.../C:/wso2/mi/.../fileName.csv.tmp(no scheme, no drive — matches customer stack trace)file:///C:/wso2/mi/.../fileName.csv.tmp✓file:///.../wso2/mi/.../fileName.csv.tmp(resolves to wrong VFS location)file:///wso2/mi/.../fileName.csv.tmp✓file:////SERVER/share/.../wso2/.../fileName.csv.tmp(no server+share)file:////SERVER/share/.../fileName.csv.tmp✓createFile()→ write →moveTo)FileSystemException)Tests Added
src/test/java/org/wso2/carbon/connector/operations/WriteFileTempFileResolutionTest.java— 10 TestNG tests (9 pass, 1 skipped if smb2 provider absent) covering:file:///C:/…— scheme + drive letter preservedfile:///…— parent-relative behaviorfile:////SERVER/share/…— server + share preservedsmb2://host/share/…— scheme + host preserved (skipped if provider unavailable)%20-encoded path — encoding preservedcreateFile()→ write →moveTo()succeedsFileSystemExceptionRun with:
(The repo's surefire config has a hard-coded
-XX:MaxPermSize=128mthat fails on JDK 9+ — direct TestNG invocation is the documented workaround until the pom'sargLineis parameterised.)Known Limitations / Follow-up
PR base branch:
esb-connector-filehas nowso2-support/*orrelease-6.0.xbranch (release branches stop atrelease-5.0.3; v6.x continues onmaster). Per the WSO2 support patch convention, a PR for a customer patch should NOT targetmaster. Maintainers should confirm whethermasteris acceptable for this patch release or whether awso2-support/6.0.xbranch should be created first.Sibling operations not fixed: The same
getName().getPath() + FILE_SEPARATOR + …concatenation pattern exists inCheckFileExist,MoveFiles, and other operations. They are explicitly out of scope for this customer-patch ticket but will fail on Windows with the same exception. A follow-up cleanup ticket againstesb-connector-fileshould be opened.pom version bump: The plan defers the
pom.xmlversion bump from6.0.2to6.0.3to release time, per connector maintainer convention.