java.util.UUID.fromString not checking length

后端 未结 5 1102
深忆病人
深忆病人 2021-01-17 09:34

When I looked into the implementation of java.util.UUID.fromString, I found that it doesn\'t check for the UUID length. Is there any particular reason for this?

5条回答
  •  逝去的感伤
    2021-01-17 10:22

    A copy of ams's answer but for scala xD

    def isValidUuid(uuid: String): Boolean =
        try uuid != null && UUID.fromString(uuid).toString.equals(uuid)
        catch {
          case e: IllegalArgumentException => false
        }
    

提交回复
热议问题