-
Notifications
You must be signed in to change notification settings - Fork 270
Description
Summary
Version 2.21.0 of the versions-maven-plugin randomly fails with ArrayIndexOutOfBoundsException in PatternIncludesArtifactFilter.addFilteredArtifact() during the use-latest-versions goal execution.
Environment
Plugin Version: 2.21.0
Maven Version: 3.x
Java Version: 11 (based on stacktrace)
Build Configuration: -T 1 (single-threaded Maven build)
Command
mvn org.codehaus.mojo:versions-maven-plugin:2.21.0:use-latest-versions \
-DgenerateBackupPoms=false \
'-Dincludes=com.example:*,com.example.*:*' \
-DallowSnapshots=false \
-DprocessParent=true \
-DallowMajorUpdates=false \
-DallowMinorUpdates=true \
-DallowIncrementalUpdates=true \
-e \
--batch-mode \
-T 1
Error
The build fails randomly with:
[ERROR] Failed to execute goal org.codehaus.mojo:versions-maven-plugin:2.21.0:use-latest-versions (default-cli) on project my-project: Execution default-cli of goal org.codehaus.mojo:versions-maven-plugin:2.21.0:use-latest-versions failed: java.lang.ArrayIndexOutOfBoundsException: Index 11 out of bounds for length 10
Caused by: java.util.concurrent.CompletionException: java.lang.ArrayIndexOutOfBoundsException: Index 11 out of bounds for length 10
at java.util.concurrent.CompletableFuture.encodeThrowable (CompletableFuture.java:314)
at java.util.concurrent.CompletableFuture.completeThrowable (CompletableFuture.java:319)
at java.util.concurrent.CompletableFuture$AsyncRun.run (CompletableFuture.java:1739)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1128)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:628)
at java.lang.Thread.run (Thread.java:829)
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 11 out of bounds for length 10
at java.util.ArrayList.add (ArrayList.java:487)
at java.util.ArrayList.add (ArrayList.java:499)
at org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter.addFilteredArtifact (PatternIncludesArtifactFilter.java:147)
at org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter.include (PatternIncludesArtifactFilter.java:101)
at org.codehaus.mojo.versions.AbstractVersionsDependencyUpdaterMojo.isIncluded (AbstractVersionsDependencyUpdaterMojo.java:368)
at org.codehaus.mojo.versions.UseLatestVersionsMojoBase.lambda$getUpdates$1 (UseLatestVersionsMojoBase.java:287)
at java.util.concurrent.CompletableFuture$AsyncRun.run (CompletableFuture.java:1736)
Different runs produce different index values in the error message (e.g., "Index 1 out of bounds for length 0", "Index 11 out of bounds for length 10"), confirming the race condition nature.
Analysis
The stacktrace shows the error originates from CompletableFuture asynchronous execution within the plugin. Even though Maven is configured with -T 1 (single-threaded), the plugin appears to use internal parallel processing via CompletableFuture for dependency metadata downloads.
The PatternIncludesArtifactFilter.addFilteredArtifact() method uses non-thread-safe ArrayList operations, which are being accessed concurrently by multiple threads downloading metadata in parallel. This causes concurrent modification and array bounds violations.
Pattern Impact: Occurs with both simple patterns (com.example*:) and complex patterns (com.example:,com.example.:)
Expected Behavior
The plugin should handle parallel metadata downloads with thread-safe collections or proper synchronization, ensuring stable execution regardless of the number of matching dependencies.