Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make the code compliant with: Move this variable to comply with Java Code Conventions

I have the following class:

public final class AppConst {
    private AppConst() {}
        
    public static final String READ_ERROR = "READ";
    public static final String PROCESS_ERROR = "PROCESS";
    public static final String WRITE_ERROR = "WRITE";
}

SonarQube marks errors on all three lines with the variables:

Move this variable to comply with Java Code Conventions.

How to make the code compliant with SonarQube?

I'm using SonarLint for Eclipse v2.6.0.

like image 822
Jeff Cook Avatar asked Dec 05 '25 08:12

Jeff Cook


1 Answers

The issue is found by the RSPEC-1213 The members of an interface or class declaration should appear in a pre-defined order rule. The description says:

According to the Java Code Conventions as defined by Oracle, the members of a class or interface declaration should appear in the following order in the source files:

  • Class and instance variables
  • Constructors
  • Methods

Your code contains a constructor before the variables. Valid code:

public final class AppConst {   
    public static final String READ_ERROR = "READ";
    public static final String PROCESS_ERROR = "PROCESS";
    public static final String WRITE_ERROR = "WRITE";

    private AppConst() {}
}
like image 173
agabrys Avatar answered Dec 08 '25 06:12

agabrys



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!