Hi there, I’ve hit something I think is a false positive, involving lombok’s “SuperBuilder” annotation. The reported code smell is S3252
- We are using SonarCloud
- Sample Code (this is not code I have run through it, but a summary of the code I have that triggers it) -
@SuperBuilder
@NoArgsConstructor
public class BaseClass<T, R> {
@Getter
private String itemId;
@Getter
private R item1;
@Getter
private T item2;
}
@NoArgsConstructor
public UtilityClass {
@SuperBuilder
protected static class SubClass extends BaseClass<String, String> {
@Getter
String anotherId;
@Getter
String andAnotherId;
}
public void doSomething() {
SubClass subClass = SubClass.builder().anotherId("a").andAnotherId("b").itemId("c").item1("d").item2("e").build();
}
}
The SuperBuilder annotation gives the subclass a method - builder() - which can also be used to set attributes in the superclass as well, avoiding the need for constructor boilerplate. Sonarcloud raises issue S3252 against the call to SubClass.builder(), and appears to be telling me I ought to use the BaseClass.builder(), but that’s wrong here.