Skip to content

Fix IllegalStateException when cache is disabled via command line#424

Merged
olamy merged 2 commits into
apache:masterfrom
cowwoc:fix-cache-disabled-staging
Jan 7, 2026
Merged

Fix IllegalStateException when cache is disabled via command line#424
olamy merged 2 commits into
apache:masterfrom
cowwoc:fix-cache-disabled-staging

Conversation

@cowwoc

@cowwoc cowwoc commented Jan 6, 2026

Copy link
Copy Markdown
Contributor

Summary

When running with -Dmaven.build.cache.enabled=false, the build fails with:

IllegalStateException: Cache is not initialized. Actual state: DISABLED

This occurs because stagePreExistingArtifacts() was being called unconditionally, which internally calls collectCachedArtifactPaths(), which then calls cacheConfig.getAttachedOutputs(). The getAttachedOutputs() method calls checkInitializedState() which throws when the cache state is DISABLED.

Fix

Add a check for cacheState == INITIALIZED before calling stagePreExistingArtifacts() and restoreStagedArtifacts(), ensuring these cache-dependent operations are only performed when the cache is properly initialized.

Test plan

  • Build compiles successfully
  • Run existing tests to verify no regressions
  • Manual test: run mvn clean install -Dmaven.build.cache.enabled=false on a project with the extension - should no longer fail

Fixes the regression reported in #394 (comment)

When running with -Dmaven.build.cache.enabled=false, the build would
fail with IllegalStateException: "Cache is not initialized. Actual
state: DISABLED" because stagePreExistingArtifacts() was being called
unconditionally.

This commit adds a check for cacheState == INITIALIZED before calling
stagePreExistingArtifacts() and restoreStagedArtifacts(), ensuring
these cache-dependent operations are only performed when the cache is
properly initialized.

Fixes the regression reported in PR apache#394 comment.
Adds a test that verifies builds succeed when cache is disabled with
-Dmaven.build.cache.enabled=false. This tests the fix for the regression
where stagePreExistingArtifacts() was called without checking if the
cache was initialized.
@cowwoc

cowwoc commented Jan 6, 2026

Copy link
Copy Markdown
Contributor Author

The build is failing due to infrastructure problems:

org.apache.maven.plugin.PluginResolutionException: Plugin org.apache.maven.plugins:maven-wrapper-plugin:3.3.4 or one of its dependencies could not be resolved:
The following artifacts could not be resolved: org.apache.maven.plugins:maven-wrapper-plugin:pom:3.3.4 (absent): Could not transfer artifact org.apache.maven.plugins:maven-wrapper-plugin:pom:3.3.4 from/to central (https://repo.maven.apache.org/maven2): status code: 403, reason phrase: Forbidden (403)

@olamy olamy added the bug Something isn't working label Jan 7, 2026
@olamy olamy added this to the 1.2.2 milestone Jan 7, 2026
@olamy olamy merged commit ac44ccb into apache:master Jan 7, 2026
26 of 28 checks passed
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.

2 participants