8240734: ModuleHashes attribute not reproducible between builds

Reviewed-by: alanb
This commit is contained in:
Dongbo He 2020-03-09 18:21:58 +08:00 committed by Fei Yang
parent aac5b27b6a
commit f4b5488181
2 changed files with 6 additions and 4 deletions

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -34,6 +34,7 @@ import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.TreeMap;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
@ -134,7 +135,7 @@ public final class ModuleHashes {
* @return ModuleHashes that encapsulates the hashes * @return ModuleHashes that encapsulates the hashes
*/ */
public static ModuleHashes generate(Map<String, Path> map, String algorithm) { public static ModuleHashes generate(Map<String, Path> map, String algorithm) {
Map<String, byte[]> nameToHash = new HashMap<>(); Map<String, byte[]> nameToHash = new TreeMap<>();
for (Map.Entry<String, Path> entry: map.entrySet()) { for (Map.Entry<String, Path> entry: map.entrySet()) {
String name = entry.getKey(); String name = entry.getKey();
Path path = entry.getValue(); Path path = entry.getValue();

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -34,6 +34,7 @@ import java.util.ArrayDeque;
import java.util.Collections; import java.util.Collections;
import java.util.Deque; import java.util.Deque;
import java.util.HashMap; import java.util.HashMap;
import java.util.TreeMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -98,7 +99,7 @@ public class ModuleHashesBuilder {
// the modules to record the hashes - it is the first matching // the modules to record the hashes - it is the first matching
// module and has not been hashed during the traversal. // module and has not been hashed during the traversal.
Set<String> mods = new HashSet<>(); Set<String> mods = new HashSet<>();
Map<String, ModuleHashes> hashes = new HashMap<>(); Map<String, ModuleHashes> hashes = new TreeMap<>();
builder.build() builder.build()
.orderedNodes() .orderedNodes()
.filter(mn -> roots.contains(mn) && !mods.contains(mn)) .filter(mn -> roots.contains(mn) && !mods.contains(mn))