public static Uuid fromString(String str) {
        if (str.length() > 24) {
            throw new IllegalArgumentException("Input string with prefix `"
                + str.substring(0, 24) + "` is too long to be decoded as a base64 UUID");
        }

        ByteBuffer uuidBytes = ByteBuffer.wrap(Base64.getUrlDecoder().decode(str));
        if (uuidBytes.remaining() != 16) {
            throw new IllegalArgumentException("Input string `" + str + "` decoded as "
                + uuidBytes.remaining() + " bytes, which is not equal to the expected 16 bytes "
                + "of a base64-encoded UUID");
        }

        return new Uuid(uuidBytes.getLong(), uuidBytes.getLong());
    }
@Test
    public void testFromStringWithInvalidInput() {
        String oversizeString = Base64.getUrlEncoder().withoutPadding().encodeToString(new byte[32]);
        assertThrows(IllegalArgumentException.class, () -> Uuid.fromString(oversizeString));

        String undersizeString = Base64.getUrlEncoder().withoutPadding().encodeToString(new byte[4]);
        assertThrows(IllegalArgumentException.class, () -> Uuid.fromString(undersizeString));
    }