GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix #12583: Inverted file existence check in DefaultTransport.put() by elharo · Pull Request #12612 · apache/maven

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@elharo
elharo requested a review from Copilot July 29, 2026 14:10
gnodet
gnodet reviewed Jul 29, 2026
View reviewed changes

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

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 parameter — testPutBytesSucceeds 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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Copilot started reviewing on behalf of elharo July 29, 2026 14:27
View session
Copilot AI reviewed Jul 29, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultTransportTest.java Outdated
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 thread impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultTransportTest.java
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));
}
Comment thread impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultTransportTest.java Outdated
}

@Test
void testPutBytesSucceeds(@TempDir Path tempDir) {
elharo and others added 2 commits July 29, 2026 17:55
@elharo @gnodet
fix apache#12583: Inverted file existence check in DefaultTransport.p…
8bb0c27
…ut()
@gnodet @claude
Address review comments: improve test robustness
c67af90
- 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 <[email protected]>
@gnodet
gnodet force-pushed the fix-12583 branch from 5f27eec to c67af90 Compare July 29, 2026 15:57
gnodet
gnodet approved these changes Jul 29, 2026
View reviewed changes

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@gnodet
gnodet merged commit 286b463 into apache:master Jul 29, 2026
22 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added this to the 4.1.0 milestone Jul 29, 2026
@github-actions

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot assigned gnodet Jul 29, 2026
@gnodet gnodet mentioned this pull request Jul 29, 2026
[backport maven-4.0.x] fix #12583: Inverted file existence check in DefaultTransport.put() #12619
Merged
@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
@gnodet
Fix #12583: Inverted file existence check in DefaultTransport.put()
3789769
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

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@gnodet gnodet gnodet approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@gnodet gnodet

Labels

bug Something isn't working

Projects

None yet

Milestone

4.2.0

Development

Successfully merging this pull request may close these issues.

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

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@elharo @gnodet
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.