You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reading a property which is configured with finalizeValueOnRead() sometimes fails with this exception:
java.lang.UnsupportedOperationException: Valued object is in an unexpected state.
at org.gradle.api.internal.provider.ValueState$FinalizedValue.unexpected(ValueState.java:401)
at org.gradle.api.internal.provider.ValueState$FinalizedValue.forUpstream(ValueState.java:340)
at org.gradle.api.internal.provider.AbstractProperty.finalizeNow(AbstractProperty.java:281)
at org.gradle.api.internal.provider.AbstractProperty.lambda$beforeRead$0(AbstractProperty.java:276)
at org.gradle.api.internal.provider.ValueState.finalizeOnReadIfNeeded(ValueState.java:123)
at org.gradle.api.internal.provider.AbstractProperty.beforeRead(AbstractProperty.java:276)
at org.gradle.api.internal.provider.AbstractProperty.beforeRead(AbstractProperty.java:268)
at org.gradle.api.internal.provider.AbstractProperty.calculateOwnValue(AbstractProperty.java:162)
at org.gradle.api.internal.provider.AbstractMinimalProvider.calculateOwnPresentValue(AbstractMinimalProvider.java:80)
at org.gradle.api.internal.provider.AbstractMinimalProvider.get(AbstractMinimalProvider.java:100)
Expected Behavior
Reading the property should be successful.
Context (optional)
A single extension exists on the rootProject. This allows configuring multiple tasks, one for each project, with a global configuration. Since the tasks have no dependencies between them, they can run in parallel.
Steps to Reproduce
An example project can be found at https://github.com/SaschaRiemer/gradle-concurrent-property
However, the error does not occur reliably. Execute "./gradlew myTask", and there is a chance that the build will fail with an exception. It can happen immediately, or take 50 tries, eventually, when executing the command often enough, it should occur.
However, after analyzing the source code, I believe the problem to be this:
An extension is created on the rootProject, this extension has a ListProperty
The property is configured as finalizeValueOnRead()
For each project, a task is created. The task, during execution, accesses that property
This can cause concurrent access to the property, because the tasks are executed in parallel.
Then, there is a race condition:
Two threads, say Thread 1 and Thread 2, concurrently execute two of these tasks
Both read the property, and first check whether the property needs to be finalized
Since the property is not yet finalized, this check returns true for both tasks
Thread 1 now finalized the value, i.e. it swaps AbstractProperty.state to a FinalizedValue
Then, Thread 2 also tries to finalize the value, effectively calling ValueState.forUpstream on a FinalizedValue, which throws an exception
Gradle version
8.7
Build scan URL (optional)
No response
Your Environment (optional)
No response
The text was updated successfully, but these errors were encountered:
Current Behavior
Reading a property which is configured with finalizeValueOnRead() sometimes fails with this exception:
Expected Behavior
Reading the property should be successful.
Context (optional)
A single extension exists on the rootProject. This allows configuring multiple tasks, one for each project, with a global configuration. Since the tasks have no dependencies between them, they can run in parallel.
Steps to Reproduce
An example project can be found at https://github.com/SaschaRiemer/gradle-concurrent-property
However, the error does not occur reliably. Execute "./gradlew myTask", and there is a chance that the build will fail with an exception. It can happen immediately, or take 50 tries, eventually, when executing the command often enough, it should occur.
However, after analyzing the source code, I believe the problem to be this:
Then, there is a race condition:
Gradle version
8.7
Build scan URL (optional)
No response
Your Environment (optional)
No response
The text was updated successfully, but these errors were encountered: