Skip to content

AnnotationOnSameLine: FalseNegative when the annotation is on the same line of the modifer of the target class #15161

@mahfouz72

Description

@mahfouz72

Check documentation : https://checkstyle.org/checks/annotation/annotationonsameline.html#AnnotationOnSameLine


PS D:\CS\test> javac src/Test.java                                               
PS D:\CS\test> cat config.xml                                                    
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
          "https://checkstyle.org/dtds/configuration_1_3.dtd">

<module name="Checker">
  <module name="TreeWalker">
    <module name="AnnotationOnSameLine"/>
  </module>
</module>

PS D:\CS\test> cat src/Test.java                                                 
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.TYPE_USE;

public  class Test {
  @Ann public   // expected violation
  @Ann2 class E {}

  @Ann private  //  expected violation
  @Ann2 class A {}

  @Ann sealed  //  expected violation
  @Ann2 class B permits C {}

  @Ann final  //  expected violation
  @Ann2 class C extends B {}


  @Target({TYPE_USE}) @interface Ann {}
  @Target({TYPE_USE}) @interface Ann2 {}
}

PS D:\CS\test> java  -jar checkstyle-10.17.0-all.jar -c config.xml  src/Test.java
Starting audit...
Audit done.

The annotation is on the same line with the modifier of the target class, not the target class itself so I expect violations for the above example

Metadata

Metadata

Assignees

No one assigned

    Labels

    approvedbugfalse negativeissues where check should place violations on code, but does not

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions