Skip to content

Instantly share code, notes, and snippets.

@Szer
Szer / UUID.parse.kt
Last active July 6, 2021 17:02
Parsing of UUID
import java.util.*
import java.util.UUID
// java.util.UUID.fromString doesn't enforce string representation of UUID https://www.ietf.org/rfc/rfc4122.txt
// It requires 4 '-' to present with any hex numbers in between. So it treats 1-1-1-1-1 as a valid UUID
// I don't think it's valid string representation of UUID. RFC4122 also doesn't think so
// Open JDK bug: https://bugs.openjdk.java.net/browse/JDK-8216407
// That's why we have our own UUID parser here
// Taken from here https://github.com/openjdk/jdk/blob/f485171ce8c7e9c9d7d2c24e1807efaa6ff137e8/src/java.base/share/classes/java/util/UUID.java#L212-L259
// But without "wrong" part