JDK-8277166 : Data race in jdeps VersionHelper
  • Type: Bug
  • Component: tools
  • Affected Version: 18
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2021-11-16
  • Updated: 2022-03-17
  • Resolved: 2021-11-26
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 17 JDK 18
17.0.4-oracleFixed 18 b26Fixed
Related Reports
Relates :  
Relates :  
Description
There's a data race in the following code in VersionHelper:

                if (nameToVersion.containsKey(name)) {
                    if (!version.equals(nameToVersion.get(name))) {
                        throw new MultiReleaseException(
                                "err.multirelease.version.associated",
                                name, nameToVersion.get(name), version
                        );
                    }
                } else {
                    nameToVersion.put(name, version);
                }

2 threads might be running this code concurrently. Both threads could first run the nameToVersion.containsKey(name) check, see false as the result, and then both continue to the else block to put the result in the nameToVersion map, where 1 of the 2 threads will end up overwriting the value the other thread inserted.
Comments
A pull request was submitted for review. URL: https://git.openjdk.java.net/jdk17u-dev/pull/256 Date: 2022-03-15 09:34:18 +0000
15-03-2022

Changeset: 7e54d065 Author: Mandy Chung <mchung@openjdk.org> Date: 2021-11-26 01:55:58 +0000 URL: https://git.openjdk.java.net/jdk/commit/7e54d065a17f1277adf1b8561fadb8a480bc6bed
26-11-2021

Suggest maybe re-writing the code using putIfAbsent: String prevVersion = nameToVersion.putIfAbsent(name, version); if (prevVersion != null && !prevVersion.equals(version)) { throw new MultiReleaseException( "err.multirelease.version.associated", name, prevVersion, version ); } I think then only 1 thread will be able to insert a value.
17-11-2021