Skip to content

Fix repository filename lookup without a directory - #252

Open
akashchamp wants to merge 2 commits into
apache:masterfrom
akashchamp:fix/repository-filename-without-directory
Open

akashchamp wants to merge 2 commits into
apache:masterfrom
akashchamp:fix/repository-filename-without-directory

Conversation

@akashchamp

@akashchamp akashchamp commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Closes #248

What and why

CompareMojo.getRepositoryFilename() assumes the local repository manager always returns a path containing / and slices the string at the last separator. A local repository manager may return a bare filename instead, which makes path.substring(path.lastIndexOf('/')) throw StringIndexOutOfBoundsException before the comparison result is written. Use Path file-name extraction so both bare filenames and nested repository paths resolve to the artifact filename.

Validation

  • New integration test compare-flat-local-repository: a setup-flat-local-repository project builds a small core extension that wraps the default local repository manager so getPathForLocalArtifact() returns a bare filename (activated with -DflatLocalRepository=true on the rebuild only). The IT installs a reference build, rebuilds with the flat layout and runs artifact:compare; verify.groovy checks that the extension was active, that no StringIndexOutOfBoundsException occurred and that the expected .buildcompare (with the diffoscope hint) was written. Without the fix the IT fails with the exception from compare: getRepositoryFilename crashes on path without '/' #248.
  • mvn verify passed.
  • mvn -Prun-its verify passed with Maven 3.9.16; the new IT also passes with Maven 3.10.0-rc-1 and Maven 4.0.0-rc-6.

Checklist

  • This pull request addresses one issue without unrelated changes.
  • The commit has a meaningful subject and body.
  • Tests cover the behavioral change.
  • mvn verify passed.
  • mvn -Prun-its verify passed.
  • I hereby declare this contribution to be licenced under the Apache License Version 2.0, January 2004.

Comment thread src/main/java/org/apache/maven/plugins/artifact/buildinfo/CompareMojo.java Outdated
Comment thread src/test/java/org/apache/maven/plugins/artifact/buildinfo/CompareMojoTest.java Outdated
@akashchamp
akashchamp force-pushed the fix/repository-filename-without-directory branch from 1e160d8 to 27078d6 Compare September 20, 2026 15:36
@akashchamp
akashchamp force-pushed the fix/repository-filename-without-directory branch from 27078d6 to 3b72fe0 Compare October 8, 2026 18:44
Use Path file-name extraction so a local repository manager may return either a bare filename or a nested repository path.
Keep getRepositoryFilename() private with its original signature so the
change is limited to the filename extraction, and replace the unit test
that was coupled to the implementation with an invoker integration test.

The compare-flat-local-repository IT uses a core extension, built by the
setup-flat-local-repository project, that wraps the default local
repository manager so getPathForLocalArtifact() returns a bare filename
without any directory on the rebuild. Without the fix, artifact:compare
fails with StringIndexOutOfBoundsException.
@akashchamp
akashchamp force-pushed the fix/repository-filename-without-directory branch from 3b72fe0 to 720d9b7 Compare October 9, 2026 19:43
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.

compare: getRepositoryFilename crashes on path without '/'

2 participants