SonarQube Java
  1. SonarQube Java
  2. SONARJAVA-254

Rule: Exception classes should be immutable and so all their fields should be final

    Details

    • Type: New Feature New Feature
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.4
    • Component/s: Rules
    • Labels:
      None
    • Number of attachments :
      0

      Issue Links

        Activity

        Hide
        Dinesh Bolkensteyn added a comment -

        There are 2 ways to implement this rule, both having their pros and cons:

        1) Work on the AST. We know that a class is an exception if its name ends with 'Exception', which is not 100% accurate. But then we can report the issues exactly on the line of each field.

        2) We work on the bytecode, we know for sure if a class is an exception or not, but we cannot log the issues on the lines where the fields are declared.

        I've opted for the solution 1) for the time being.

        Obviously, we'll be able to improve this rule one the symbol table will be available from AST checks to get rid off the approximation.

        Show
        Dinesh Bolkensteyn added a comment - There are 2 ways to implement this rule, both having their pros and cons: 1) Work on the AST. We know that a class is an exception if its name ends with 'Exception', which is not 100% accurate. But then we can report the issues exactly on the line of each field. 2) We work on the bytecode, we know for sure if a class is an exception or not, but we cannot log the issues on the lines where the fields are declared. I've opted for the solution 1) for the time being. Obviously, we'll be able to improve this rule one the symbol table will be available from AST checks to get rid off the approximation.
        Hide
        Dinesh Bolkensteyn added a comment -

        Done

        Show
        Dinesh Bolkensteyn added a comment - Done
        Hide
        Dinesh Bolkensteyn added a comment -

        Note that Checkstyle also seems to go for option 1) as it takes a regular expression to define what an exception class is.

        Show
        Dinesh Bolkensteyn added a comment - Note that Checkstyle also seems to go for option 1) as it takes a regular expression to define what an exception class is.
        Hide
        Freddy Mallet added a comment -

        Works well Dinesh but could you just change the issue message :

        "Make this field 'xxxx' final" instead of "Make this field final"

        Thanks

        Show
        Freddy Mallet added a comment - Works well Dinesh but could you just change the issue message : "Make this field 'xxxx' final" instead of "Make this field final" Thanks
        Hide
        Freddy Mallet added a comment -

        And due to the following UI bug : SONAR-4562, could you remove usage of HTML list in the rule description ?

        Show
        Freddy Mallet added a comment - And due to the following UI bug : SONAR-4562 , could you remove usage of HTML list in the rule description ?
        Hide
        Dinesh Bolkensteyn added a comment -

        Should be fixed

        Show
        Dinesh Bolkensteyn added a comment - Should be fixed
        Hide
        Freddy Mallet added a comment -

        Manually tested !

        Show
        Freddy Mallet added a comment - Manually tested !

          People

          • Assignee:
            Dinesh Bolkensteyn
            Reporter:
            Freddy Mallet
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: