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

javac parser generates incorrect end position for annotations with parentheses.

XMLWordPrintable

    • b03
    • generic
    • generic
    • Verified

      The javac parser stores the end position for annotations, which cannot be heuristically determined because parentheses can be optional in an annotation expression. However, it always stores the end position of the annotation's identifier, rather than the closing parenthesis when parentheses are present:

         @SuppressWarning("foo")
      ------------------^ current endPos stored in endPositions
      -------------------------^ correct endPos

      The problem is that com.sun.tools.javac.parser.Parser.annotation() stores the identifier's end position before parsing any fields, then stores that value regardless of whether there were any parentheses. The suggested fix checks whether the next token is a left-parenthesis, and if so uses the last token's end position, otherwise the stored value. Although there isn't a test case, this fix was verified with Jackpot.

            ahe Peter Ahe
            tballsunw Tom Ball (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: