-
Notifications
You must be signed in to change notification settings - Fork 629
Closed
Description
SpotBugs version: 4.8.6.4 (but the bug seems to occur in all 4.8 versions)
Java: 21
Consider the attached mini project: spotbugs.tar.gz
The code passes SB versions < 4.8, but now we are getting this false positive:
package org.example;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.util.concurrent.atomic.AtomicInteger;
public class SpotBugsFalsePositiveTest {
private AtomicInteger initializedMember;
@BeforeClass
public void setup() {
initializedMember = new AtomicInteger();
}
@Test
public void testSyncMasterData() {
Assert.assertEquals(initializedMember.get(), 0);
}
}
Expected Behaviour: the code should pass SB, because @BeforeClass
is supposed to be treated like a constructor.
Actual behaviour:
[ERROR] Low: SpotBugsFalsePositiveTest.initializedMember not initialized in constructor and dereferenced in org.example.SpotBugsFalsePositiveTest.testSyncMasterData() [org.example.SpotBugsFalsePositiveTest] At SpotBugsFalsePositiveTest.java:[line 20] UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR
See also #453 from 2017 where a similar false positive was then fixed.
Metadata
Metadata
Assignees
Labels
No labels