Paul Croarkin
Paul Croarkin

Reputation: 14675

SonarQube Rules Conflict

SonarQube reported 'Make "ids" transient or serializable' for this line of code:

private final List<String> ids;

So I changed it to:

private final ArrayList<String> ids;

and made sure that my public interface (the constructor in this case) still used just an interface:

public MyClass(List<String> ids) {
    this.ids = (ids == null) ? new ArrayList<>() : new ArrayList<>(ids);
}

This got rid of the first SonarQube warning, but now it gives:

The type of the "ids" object should be an interface such as "List" rather than the implementation "ArrayList".

I don't want to turn off all rules for using interfaces rather than concrete classes, but only for cases like this.

Upvotes: 0

Views: 328

Answers (1)

G. Ann - SonarSource Team
G. Ann - SonarSource Team

Reputation: 22794

You don't say what version of the Java plugin you're using, but it's likely pre-3.4; that rule was relaxed in v3.4 to ignore private fields.

Upvotes: 1

Related Questions