--- old/src/java.base/share/classes/java/util/UUID.java 2020-03-08 09:12:45.803466895 +0100 +++ new/src/java.base/share/classes/java/util/UUID.java 2020-03-08 09:12:45.597470573 +0100 @@ -223,17 +223,56 @@ * Creates a {@code UUID} from the string standard representation as * described in the {@link #toString} method. * + * @param uuidString + * A string that specifies a {@code UUID} + * + * @return A {@code UUID} with the specified value + * + * @throws IllegalArgumentException + * If {@code uuidString} does not conform to the string representation as + * described in {@link #toString} + * + * @since 15 + */ + public static UUID valueOf(String uuidString) { + UUID uuid = valueOf1(uuidString); + if (uuid == null) { + throw new IllegalArgumentException("Invalid UUID string: " + uuidString); + } + return uuid; + } + + /** + * Creates a {@code UUID} from the string standard representation as + * described in the {@link #toString} method. + * * @param name * A string that specifies a {@code UUID} * * @return A {@code UUID} with the specified value * * @throws IllegalArgumentException - * If name does not conform to the string representation as + * If name does not conform loosely to the string representation as * described in {@link #toString} * + * @deprecated Since it allows invalid input strings to be converted to + * UUID instances. For example: + * + * Use {@link #valueOf(String)} instead. */ + @Deprecated public static UUID fromString(String name) { + UUID uuid = valueOf1(name); + return uuid != null ? uuid : fromString1(name); + } + + private static UUID valueOf1(String name) { if (name.length() == 36) { char ch1 = name.charAt(8); char ch2 = name.charAt(13); @@ -255,7 +294,7 @@ } } } - return fromString1(name); + return null; } private static UUID fromString1(String name) {