tree-sitter-java icon indicating copy to clipboard operation
tree-sitter-java copied to clipboard

Parsing error for annotations before spread parameter

Open theawless opened this issue 7 months ago • 2 comments

Hi folks, thank you for creating this brilliant package! I was parsing some java code when I noticed some errors.

tree-sitter: 0.25.4 tree-sitter-java: 0.23.5

Sample code that is breaking:

public class B38203081 {
    void g(int @A [] @B ... xs) {
    }
}
program [0, 0] - [4, 0]
  class_declaration [0, 0] - [3, 1]
    modifiers [0, 0] - [0, 6]
      public [0, 0] - [0, 6]
    class [0, 7] - [0, 12]
    name: identifier [0, 13] - [0, 22]
    body: class_body [0, 23] - [3, 1]
      { [0, 23] - [0, 24]
      ERROR [1, 4] - [2, 5]
        void_type [1, 4] - [1, 8]
        identifier [1, 9] - [1, 10]
        ( [1, 10] - [1, 11]
        integral_type [1, 11] - [1, 14]
          int [1, 11] - [1, 14]
        marker_annotation [1, 15] - [1, 17]
          @ [1, 15] - [1, 16]
          name: identifier [1, 16] - [1, 17]
        [ [1, 18] - [1, 19]
        ] [1, 19] - [1, 20]
        marker_annotation [1, 21] - [1, 30]
          @ [1, 21] - [1, 22]
          name: scoped_identifier [1, 22] - [1, 30]
            scope: identifier [1, 22] - [1, 23]
            . [1, 24] - [1, 25]
            ERROR [1, 25] - [1, 27]
              . [1, 25] - [1, 26]
              . [1, 26] - [1, 27]
            name: identifier [1, 28] - [1, 30]
        ) [1, 30] - [1, 31]
        { [1, 32] - [1, 33]
        } [2, 4] - [2, 5]
      } [3, 0] - [3, 1]

This is a working java snippet https://ideone.com/83Nz5C and utilizes type use annotations https://docs.oracle.com/javase/tutorial/java/annotations/type_annotations.html which I believe is a rarely used feature.

theawless avatar Jun 05 '25 05:06 theawless

I just came here to report the same issue.

Found a few errors in the spring-framework repo, for example, the third parameter in this method causes an ERROR.

https://github.com/spring-projects/spring-framework/blob/main/spring-core/src/main/java/org/springframework/util/ClassUtils.java#L1277-L1290

It seems like the PR hasn't been approved yet. Any idea how to get this fix approved?

streichsbaer avatar Jul 14 '25 06:07 streichsbaer

@streichsbaer we're waiting for the maintainer to review the fix

theawless avatar Jul 16 '25 15:07 theawless