Manoj Kumar
Manoj Kumar

Reputation: 1

Make this field as final facing an issue in sonarqube code smells?

I am running my spring boot apps through jenkins sonarqube, where i face an issue in code smell as making a field as final in the custom exception class which extends RuntimeException Below is my code

@Getter
@Setter
public class CustomException extends RuntimeException {

    /**
     * 
     */
    private static final long serialVersionUID = -7436800211172984660L;

    private Exception exception;
    private JsonException jsonException;

    public CustomException(Exception exception) {
        this.exception = exception;
    }

    public CustomException(JsonException jsonException) {
        this.jsonException = jsonException;
    }
    
}

Here is the sonar code smell issue Code smell issue highlighting

If i declare as final then the constructor shows compile error as The blank final field exception may not have been initialized Can anyone help me out on this issue.

Upvotes: 0

Views: 607

Answers (1)

ecagiral
ecagiral

Reputation: 3

Did you try to add setter methods instead of annotations? Maybe code smell trigger is unable to see that excepion can be set after object is constructed.

But also I believe that this is really a code smell that you have multiple properties for different representations of the same data.

Upvotes: 0

Related Questions