RFR: 8290041: ModuleDescriptor.hashCode is inconsistent [v2]
Alan Bateman
alanb at openjdk.org
Mon Aug 15 16:12:33 UTC 2022
On Thu, 11 Aug 2022 14:16:51 GMT, Jaikiran Pai <jpai at openjdk.org> wrote:
>> Can I please get a review of this change which proposes to fix https://bugs.openjdk.org/browse/JDK-8290041?
>>
>> As noted by the reporter, the current implementation is buggy since the calculation can result in a different value of the hashcode depending on the order of iteration of the `Modifier`s. The commit in this PR changes that computation to produce consistent result irrespective of the order in which the `Modifier`s (enum) is iterated upon.
>>
>> A new test has been added which reproduces the issue and verifies the fix.
>
> Jaikiran Pai has updated the pull request incrementally with one additional commit since the last revision:
>
> incorporate review comments and add more testing
src/java.base/share/classes/java/lang/module/ModuleDescriptor.java line 2630:
> 2628: int h = 0;
> 2629: for (Enum<?> e : enums) {
> 2630: h += e.name().hashCode();
Good
test/jdk/java/lang/module/ModuleDescriptorHashCodeTest.java line 83:
> 81: final Set<ModuleDescriptor.Opens.Modifier> mods2 = Set.of(
> 82: ModuleDescriptor.Opens.Modifier.MANDATED, ModuleDescriptor.Opens.Modifier.SYNTHETIC);
> 83: final ModuleDescriptor desc2 = createModuleDescriptor(mods2, null, null);
If you import Requires, Exports and Opens then it should mean you can fit these onto a single line and might be easier to read, e.g.
var mods2 = Set.of(Opens.Modifier.MANDATED, Opens.Modifier.SYNTHETIC);
test/jdk/java/lang/module/ModuleDescriptorHashCodeTest.java line 181:
> 179: Set<ModuleDescriptor.Exports.Modifier> expsModifiers) {
> 180:
> 181: final var mdb = ModuleDescriptor.newModule("foobar");
Does "mdb" stand for something here?
-------------
PR: https://git.openjdk.org/jdk/pull/9790
More information about the core-libs-dev
mailing list