Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8321540

ClassSignature.parseFrom() throws StringIndexOutOfBoundsException for invalid signatures

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 23
    • 22
    • core-libs

      The class signature parsing code can fail with an unexpected error on invalid input:

      jshell> ClassSignature.parseFrom("Ljava/lang/Object;Ljava/lang/Iterable<LFoo;>")
      | Exception java.lang.StringIndexOutOfBoundsException: String index out of range: 44
      | at StringLatin1.charAt (StringLatin1.java:48)
      | at String.charAt (String.java:1517)
      | at SignaturesImpl.referenceTypeSig (SignaturesImpl.java:137)
      | at SignaturesImpl.parseClassSignature (SignaturesImpl.java:53)
      | at ClassSignature.parseFrom (ClassSignature.java:84)
      | at (#4:1)

      I would expect that this method be specified to throw a specific exception on parse failure, and for the underlying code to then be consistent with that specification.

      This was reported by a user using my downstream backport of this API to Java 17: https://github.com/dmlloyd/jdk-classfile-preview/issues/15 and also relates to JDK-8320360.

            asotona Adam Sotona
            dmlloyd David Lloyd
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: