bernda
(Bernda Darneb)
April 22, 2021, 9:17pm
1
When using Lomboks @SuperBuilder (lombok.experimental.SuperBuilder
) on immutable classes sonarqube reports that the field should be static too (S1170 - Make this final field static too.
). However the Builder generated by Lombok will use this value as default/fallback value when initializing an entity.
Example:
This is basically the same issue as described for @lombok.Builder
(already fixed/implemented):
Template for a good false-positive report, formatted with Markdown :
SonarQube Version 8.5 (build 37579)
@Data
@Builder
public class MyEntity {
@Default
final boolean byDefaultTrue = true;
}
SonaQube report that I should make this static final instead of just final. But Lombok is using the value only as fallback for its Builder and is indeed initializing this field inside the BuilderClass.
and fixed
SonarSource:master
← steven-sheehy:fp-lombok-builder-default
opened 04:53PM - 06 Nov 20 UTC
Fixes [false positive](https://sonarcloud.io/project/issues?id=hedera-mirror-nod… e&issues=AXWZiS9Nv5yw_9uAtotR&open=AXWZiS9Nv5yw_9uAtotR) S1170 (e.g. `Make this final field static too.`) for final fields having `@lombok.Builder.Default`. Previously this class would fail despite being valid Java code with Lombok on the classpath:
```java
@Builder
public class Test {
@Builder.Default
private final int foo = 1;
}
```
Please ensure your pull request adheres to the following guidelines:
- [x] Use the following formatting style: [SonarSource/sonar-developer-toolset](https://github.com/SonarSource/sonar-developer-toolset#code-style)
- [x] Unit tests are passing and you provided a unit test for your fix
- [ ] ITs should pass : To run ITs locally, checkout the [README](https://github.com/SonarSource/sonar-java/blob/master/README.md) of the project.
- [x] If there is a [Jira](http://jira.sonarsource.com/browse/SONARJAVA) ticket available, please make your commits and pull request start with the ticket number (SONARJAVA-XXXX)
Hello @bernda ,
Indeed, it looks like a false positive. A ticket has been created handle the issue.
Best,
Dorian