Skip to content

Anchor VersionMapper to the trailing version segment (#374) - #380

Open
elharo wants to merge 1 commit into
masterfrom
fix-374-versionmapper
Open

Anchor VersionMapper to the trailing version segment (#374)#380
elharo wants to merge 1 commit into
masterfrom
fix-374-versionmapper

Conversation

@elharo

@elharo elharo commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #374

Summary

VersionMapper.mapFileName had two bugs:

  1. When the version was found at index 0 of the filename, substring(0, index - 1) threw a StringIndexOutOfBoundsException (e.g. setFrom("1.0"), mapFileName("1.0.jar")).
  2. indexOf matched the first occurrence of the version string, so a version appearing inside the artifactId was stripped instead of the trailing version segment (e.g. a-1.0-b-1.0.jar mapped to a-b-1.0.jar instead of a-1.0-b.jar). A version-like substring not at a segment boundary was also stripped (e.g. a-1.0b.jarab.jar).

The mapper now anchors the match to a trailing -<version> segment: it searches for -<version> from the end of the filename and only strips when the version is followed by the file extension (.), a -<classifier> segment, or nothing. Because the match always includes the leading -, the index-0 crash is impossible and the version is no longer stripped from the middle of the artifact id.

Changes

  • VersionMapper.java: replace the unanchored indexOf + substring(0, index - 1) with a lastIndexOf('-' + version) loop that validates the trailing segment boundary.
  • New unit test VersionMapperTest covering the basic case, classifier handling, the index-0 crash, the wrong-occurrence stripping, the non-boundary substring, directory preservation, and the no-match case.

Verification

  • The new tests fail on master (StringIndexOutOfBoundsException and wrong stripped filenames) and pass with the fix.
  • mvn verify (rat, checkstyle, spotless, unit tests, javadoc) passes.
  • mvn verify -Prun-its passes: all 29 integration tests succeed.

@elharo
elharo requested a review from slachiewicz August 6, 2026 09:30
@slachiewicz
slachiewicz removed their request for review August 10, 2026 20:53
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.

VersionMapper throws StringIndexOutOfBoundsException and strips wrong version occurrence

1 participant