Skip to content

[8.14 backport] TransformedClassLoader is not thread-safe #37048

@mlopatkin

Description

@mlopatkin

Current Behavior

org.gradle.internal.classloader.TransformingClassLoader is not thread-safe, because of TOCTOU:

@SuppressWarnings("deprecation")
Package p = getPackage(packageName);
if (p == null) {
definePackage(packageName, null, null, null, null, null, null, null);
}

If two callsites find the package being absent, they both proceed to define, and the last one will get IllegalArgumentException.

Expected Behavior

TransformingClassLoader should be thread-safe, because it is registered as parallel capable.

Context (optional)

With parallel CC load, some less-used Gradle classes can be loaded concurrently.

Self-contained Reproducer Project

N/A, reported internally

Gradle version

8.14

Build scan URL (optional)

No response

Your Environment (optional)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions