Uploaded image for project: 'SonarJava'
  1. SonarJava
  2. SONARJAVA-3194

Remove S3340: Annotation argument order can not be guaranteed when reading from bytecode


    • Type: Task
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 6.0
    • Fix Version/s: 6.0
    • Component/s: Rules
    • Labels:


      Rule RSPEC-3340 raise issues when parameters of an annotation are not written in the same order as they are declared in the annotation declaration.

      While this rule works very well when usages of the annotations are all in the same compilation unit (we have direct access to the annotation's declaration tree), the order can not be assumed as soon as an annotation is used from different compilation unit, and read from bytecode. Nothing in the JLS nor JVMS guarantees that order is preserved. Usage of annotation within the same compilation unit is also a corner case, and not representative of the usual usage of an annotation.

      Consequently, we can not assume that order of annotation members will be always the same, as the compilation might very well not preserve it. Javadoc of reflection API from is also quite explicit about member order.

      The elements in the returned array are not sorted and are not in any particular order.


      Because the rule can not be guaranteed as always right, rule should be dropped.

      Note that from a technical point of view, the new frontend requires the rule to be rewritten.


          Issue Links



              • Assignee:
                michael.gumowski Michael Gumowski
                michael.gumowski Michael Gumowski
              • Votes:
                0 Vote for this issue
                1 Start watching this issue


                • Created: