diff --git a/src/java.base/share/classes/java/util/UUID.java b/src/java.base/share/classes/java/util/UUID.java index ac952e81a724f..aab5f149de142 100644 --- a/src/java.base/share/classes/java/util/UUID.java +++ b/src/java.base/share/classes/java/util/UUID.java @@ -71,6 +71,14 @@ * @since 1.5 */ public final class UUID implements java.io.Serializable, Comparable<UUID> { + /** + * Special NIL UUID where all bits are set to zero, as specified in + * <a href="https://tools.ietf.org/html/rfc4122#section-4.1.7">RFC 4122 + * Section 4.1.7</a>. + * + * @since 16 + */ + public static final UUID NIL = new UUID(0, 0); /** * Explicit serialVersionUID for interoperability. diff --git a/test/jdk/java/util/UUID/UUIDTest.java b/test/jdk/java/util/UUID/UUIDTest.java index 5855c3329f42b..1aaddb686ef5f 100644 --- a/test/jdk/java/util/UUID/UUIDTest.java +++ b/test/jdk/java/util/UUID/UUIDTest.java @@ -22,7 +22,7 @@ */ /* @test - * @bug 4173528 5068772 8148936 8196334 + * @bug 4173528 5068772 8148936 8196334 8207329 * @summary Unit tests for java.util.UUID * @key randomness * @run main/othervm -XX:+CompactStrings UUIDTest @@ -36,6 +36,7 @@ public class UUIDTest { static Random generator = new Random(); public static void main(String[] args) throws Exception { + nilTest(); containsTest(); randomUUIDTest(); nameUUIDFromBytesTest(); @@ -49,6 +50,14 @@ public static void main(String[] args) throws Exception { compareTo(); } + private static void nilTest() throws Exception { + final long msb = UUID.NIL.getMostSignificantBits(); + final long lsb = UUID.NIL.getLeastSignificantBits(); + + if (msb != 0) throw new Exception("MSB of NIL UUID must be zero, got: " + msb); + if (lsb != 0) throw new Exception("LSB of NIL UUID must be zero, got: " + lsb); + } + // Verify that list.contains detects UUID collisons private static void containsTest() throws Exception { List list = new LinkedList();