sonar-findbugs
sonar-findbugs copied to clipboard
fb-contrib:USFW_UNSYNCHRONIZED_SINGLETON_FIELD_WRITES java rule caught issue in Kotlin Code
##fb-contrib:USFW_UNSYNCHRONIZED_SINGLETON_FIELD_WRITES
Environment
Component | Kotlin |
---|---|
SonarQube | 9.4 |
Sonar-FindBugs | fb-contrib:USFW_UNSYNCHRONIZED_SINGLETON_FIELD_WRITES |
Maven | ????? |
Gradle | ????? |
Java | ????? |
Code (If needed)
public class BugSample1 {
public static void hello(String message) {
//Something
Runnable r = () -> System.out.println(message);
r.run();

}
}
My understanding is that Kotlin auto-generates getters and setters, so even if they are not written, the methods will be present in the bytecode analyzed by SpotBugs. Since the setter is not synchronized the detector reports an issue.
I don't know Kotlin or Spring but from what I understand you should make these setters synchronized: https://stackoverflow.com/questions/45445991/synchronize-property-getters-setters
Thanks for your response. But I can also see other rules from java caught by findbugs plugin in Kotlin code. Below is one more example
Version 4.2.0 introduced support to report issues in Kotlin code. Unless you think that these are false positives it's a feature, not a bug ;)
I will close this as there does not seem to be further questions, please don't hesitate to create a new issue