Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AnnotationLocation: named parameters must be considered parameters. #6440

Closed
pbludov opened this Issue Feb 19, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@pbludov
Copy link
Collaborator

pbludov commented Feb 19, 2019

$ javac test.java
(no output)

$ cat config.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
    "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
    "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
  <module name="TreeWalker">
    <module name="AnnotationLocation"/>
  </module>
</module>  

$ cat test.java
@Ann("foo") class Cls1 {} // violation
@Ann(value = "foo") class Cls2 {} // no violation

@interface Ann {
    String value();
}

$ RUN_LOCALE="-Duser.language=en -Duser.country=US"
$ java $RUN_LOCALE -jar checkstyle-8.17-all.jar -c config.xml test.java
Starting audit...
[ERROR] test.java:1: Annotation 'Ann' should be alone on line. [AnnotationLocation]
Audit done.
Checkstyle ends with 1 errors.

$ java -jar checkstyle-8.17-all.jar -t test.java 
CLASS_DEF -> CLASS_DEF [1:0]
|--MODIFIERS -> MODIFIERS [1:0]
|   `--ANNOTATION -> ANNOTATION [1:0]
|       |--AT -> @ [1:0]
|       |--IDENT -> Ann [1:1]
|       |--LPAREN -> ( [1:4]
|       |--EXPR -> EXPR [1:5]                                       // EXPR here
|       |   `--STRING_LITERAL -> "foo" [1:5]
|       `--RPAREN -> ) [1:10]
|--LITERAL_CLASS -> class [1:12]
|--IDENT -> Cls1 [1:18]
`--OBJBLOCK -> OBJBLOCK [1:23]
    |--LCURLY -> { [1:23]
    `--RCURLY -> } [1:24]
CLASS_DEF -> CLASS_DEF [2:0]
|--MODIFIERS -> MODIFIERS [2:0]
|   `--ANNOTATION -> ANNOTATION [2:0]
|       |--AT -> @ [2:0]
|       |--IDENT -> Ann [2:1]
|       |--LPAREN -> ( [2:4]
|       |--ANNOTATION_MEMBER_VALUE_PAIR -> ANNOTATION_MEMBER_VALUE_PAIR [2:5]
|       |   |--IDENT -> value [2:5]
|       |   |--ASSIGN -> = [2:11]
|       |   `--EXPR -> EXPR [2:13]                               // EXPR under ANNOTATION_MEMBER_VALUE_PAIR
|       |       `--STRING_LITERAL -> "foo" [2:13]
|       `--RPAREN -> ) [2:18]
|--LITERAL_CLASS -> class [2:20]
|--IDENT -> Cls2 [2:26]
`--OBJBLOCK -> OBJBLOCK [2:31]
    |--LCURLY -> { [2:31]
    `--RCURLY -> } [2:32]

Expected two violations here. The buggy method is AnnotationLocationCheck#isParameterized

    private static boolean isParameterized(DetailAST annotation) {
        return annotation.findFirstToken(TokenTypes.EXPR) != null;
    }

There should be findFirstToken(TokenTypes.ANNOTATION_MEMBER_VALUE_PAIR) also.

@romani romani added the approved label Feb 20, 2019

pbludov added a commit to pbludov/checkstyle that referenced this issue Feb 20, 2019

pbludov added a commit to pbludov/checkstyle that referenced this issue Feb 20, 2019

pbludov added a commit to pbludov/checkstyle that referenced this issue Feb 20, 2019

pbludov added a commit to pbludov/checkstyle that referenced this issue Feb 21, 2019

romani added a commit that referenced this issue Feb 23, 2019

@romani romani added the bug label Feb 23, 2019

@romani romani added this to the 8.18 milestone Feb 23, 2019

@romani

This comment has been minimized.

Copy link
Member

romani commented Feb 23, 2019

Fix is merged

@romani romani closed this Feb 23, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.