Skip to content

fix #12583: Inverted file existence check in DefaultTransport.put() - #12612

Merged
gnodet merged 2 commits into
apache:masterfrom
elharo:fix-12583
Jul 29, 2026
Merged

fix #12583: Inverted file existence check in DefaultTransport.put()#12612
gnodet merged 2 commits into
apache:masterfrom
elharo:fix-12583

Conversation

@elharo

@elharo elharo commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

The condition Files.isRegularFile(source) in DefaultTransport.put() was inverted — it should have been !Files.isRegularFile(source). This caused put() to reject valid existing files and silently accept non-existent ones, which broke putBytes() and putString() transitively.

Fix: Added the missing ! negation operator.

Tests: Added DefaultTransportTest with tests for non-existent file rejection, valid file acceptance, and the putBytes() -> put() delegation chain.

Closes #12583

@elharo
elharo requested a review from Copilot July 29, 2026 14:10

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The core bug fix is correct — the inverted Files.isRegularFile(source) condition on line 101 of DefaultTransport.put() is properly fixed by adding the missing ! negation. The existing code was throwing IllegalArgumentException when the file IS a regular file, which is backwards per the Transport.put() API contract. The bug was introduced in the original Transport API commit (f70b001, 2022-12-01).

A few notes:

  1. Merge conflict / rebase needed — The PR is in a conflicting state because the branch was forked before commit 8134aa2 (which moved DefaultTransport.java to the org.apache.maven.impl package). The diff currently shows the entire file as new rather than the single-character fix. A rebase on current master would produce a clean, minimal diff.

  2. Unused @TempDir parametertestPutBytesSucceeds declares @TempDir Path tempDir but never uses it. It can be removed.

  3. Test assertions could be stronger — Both testPutWithExistingFileSucceeds and testPutBytesSucceeds use only assertDoesNotThrow without verifying the mock transporter's put() method was actually called. Adding verify(transporter).put(any(PutTask.class)) would confirm the delegation chain works as expected.

This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

Claude Code on behalf of gnodet

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Fixes a regression in DefaultTransport.put() where the file existence check was inverted, causing valid files to be rejected and missing files to be accepted.

Changes:

  • Corrected the Files.isRegularFile(source) guard by adding the missing negation.
  • Added JUnit tests covering missing/valid source files and putBytes() behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultTransport.java Fixes the inverted isRegularFile condition to properly validate the source file.
impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultTransportTest.java Adds tests for put() source validation and basic putBytes() success behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +37 to +42
void testPutWithNonExistentFileThrows() {
Transporter transporter = mock(Transporter.class);
DefaultTransport transport = new DefaultTransport(URI.create("http://example.com/test/"), transporter);
Path nonExistentFile = Path.of("/nonexistent/file.txt");
assertThrows(IllegalArgumentException.class, () -> transport.put(nonExistentFile, URI.create("dest.txt")));
}
Comment on lines +55 to +61
@Test
void testPutBytesSucceeds(@TempDir Path tempDir) {
Transporter transporter = mock(Transporter.class);
DefaultTransport transport = new DefaultTransport(URI.create("http://example.com/test/"), transporter);
URI dest = URI.create("dest.txt");
assertDoesNotThrow(() -> transport.putBytes("test content".getBytes(), dest));
}
}

@Test
void testPutBytesSucceeds(@TempDir Path tempDir) {
elharo and others added 2 commits July 29, 2026 17:55
- Use @tempdir for non-existent file test instead of hardcoded path
- Remove unused @tempdir parameter from testPutBytesSucceeds
- Replace assertDoesNotThrow with verify(transporter).put() to
  confirm delegation chain actually invokes the transporter

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All three findings from the previous review have been addressed:

  1. Merge conflict / rebase — resolved. The diff now cleanly shows the single-line fix.
  2. Unused @TempDir parameter — removed from testPutBytesSucceeds.
  3. Missing verify() calls — both testPutWithExistingFileSucceeds and testPutBytesSucceeds now verify that transporter.put() was actually called.

The fix is correct — the missing ! negation in the file-existence check is properly added, and the tests cover both positive and negative paths plus the putBytes delegation chain.

This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

Claude Code on behalf of gnodet

@gnodet
gnodet merged commit 286b463 into apache:master Jul 29, 2026
22 checks passed
@github-actions github-actions Bot added this to the 4.1.0 milestone Jul 29, 2026
@github-actions

Copy link
Copy Markdown

@gnodet Please assign appropriate label to PR according to the type of change.

@elharo
elharo deleted the fix-12583 branch July 29, 2026 17:50
@elharo elharo added the bug Something isn't working label Jul 29, 2026
gnodet added a commit that referenced this pull request Jul 29, 2026
The condition Files.isRegularFile(source) in DefaultTransport.put() was
inverted — it threw when the file existed and silently accepted non-existent
files, breaking putBytes() and putString() transitively. Added the missing
negation and a new DefaultTransportTest covering non-existent file rejection,
valid file acceptance, and the putBytes() delegation chain.

Backport of #12612
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[maven-4.0.x] DefaultTransport.put() has inverted file existence check

3 participants