Skip to content

Commit db4391b

Browse files
Vanitha-bpshipilev
authored andcommitted
8367598: Switch to CRC32C for SEED calculation in jdk.test.lib.Utils
Backport-of: 29908148f819281dc6d1ef1274ca4d67a47754c0
1 parent ef1e448 commit db4391b

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

test/lib/jdk/test/lib/Utils.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import java.net.URL;
3939
import java.net.URLClassLoader;
4040
import java.net.UnknownHostException;
41-
import java.nio.ByteBuffer;
4241
import java.nio.charset.StandardCharsets;
4342
import java.nio.file.CopyOption;
4443
import java.nio.file.Files;
@@ -50,8 +49,6 @@
5049
import java.nio.file.attribute.FileAttribute;
5150
import java.nio.channels.SocketChannel;
5251
import java.nio.file.attribute.PosixFilePermissions;
53-
import java.security.MessageDigest;
54-
import java.security.NoSuchAlgorithmException;
5552
import java.util.ArrayList;
5653
import java.util.Arrays;
5754
import java.util.Collection;
@@ -71,6 +68,7 @@
7168
import java.util.regex.Matcher;
7269
import java.util.regex.Pattern;
7370
import java.util.stream.Collectors;
71+
import java.util.zip.CRC32C;
7472

7573
import static java.lang.System.lineSeparator;
7674
import static jdk.test.lib.Asserts.assertTrue;
@@ -170,16 +168,11 @@ public final class Utils {
170168
var v = Runtime.version();
171169
// promotable builds have build number, and it's greater than 0
172170
if (v.build().orElse(0) > 0) {
173-
// promotable build -> use 1st 8 bytes of md5($version)
174-
try {
175-
var md = MessageDigest.getInstance("MD5");
176-
var bytes = v.toString()
177-
.getBytes(StandardCharsets.UTF_8);
178-
bytes = md.digest(bytes);
179-
SEED = ByteBuffer.wrap(bytes).getLong();
180-
} catch (NoSuchAlgorithmException e) {
181-
throw new Error(e);
182-
}
171+
// promotable build -> generate a seed based on the version string
172+
var bytes = v.toString().getBytes(StandardCharsets.UTF_8);
173+
var crc = new CRC32C();
174+
crc.update(bytes);
175+
SEED = crc.getValue();
183176
} else {
184177
// "personal" build -> use random seed
185178
SEED = new Random().nextLong();

0 commit comments

Comments
 (0)