[Task] Enable SpotBug checks disabled in 4.9.x upgrade and fix possible detected bugs
- Dominant language
- Java
- Stars
- 15.3k
- Forks
- 3.8k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 160
Description
### Search before asking
- [x] I searched in the [issues](https://github.com/apache/pulsar/issues) and found nothing similar.
### Motivation
In #24243 SpotBugs was upgraded from 4.7.3 to 4.9.3. Since new checks were introduced, the checks were disabled with the `omitVisitors` configuration to make the upgrade possible without addressing the issues in the upgrade PR.
### Solution
As a follow up, it would be necessary to enable checks to see what the actual problems are and fix them one by one.
- [ ] [ConstructorThrow](https://spotbugs.readthedocs.io/en/stable/detectors.html#constructorthrow)
- [ ] [FindPublicAttributes](https://spotbugs.readthedocs.io/en/stable/detectors.html#findpublicattributes)
- [ ] [SharedVariableAtomicityDetector](https://spotbugs.readthedocs.io/en/stable/detectors.html#sharedvariableatomicitydetector)
- [ ] [UnreadFields](https://spotbugs.readthedocs.io/en/stable/detectors.html#unreadfields)
- [ ] [MultipleInstantiationsOfSingletons](https://spotbugs.readthedocs.io/en/stable/detectors.html#multipleinstantiationsofsingletons)
- [ ] [InitializeNonnullFieldsInConstructor](https://spotbugs.readthedocs.io/en/stable/detectors.html#initializenonnullfieldsinconstructor)
- [ ] [FindNullDeref](https://spotbugs.readthedocs.io/en/stable/detectors.html#findnullderef)
### Alternatives
The checks that are unnecessarily verbose for Pulsar's code style could be kept disabled so that we don't end up adding exclusions for each occurrence like we have done for EI_EXPOSE_REP/EI_EXPOSE_REP2 bug pattern.
For example, [AT: This write of this 64-bit primitive variable may not atomic (AT_NONATOMIC_64BIT_PRIMITIVE)](https://spotbugs.readthedocs.io/en/stable/bugDescriptions.html#at-nonatomic-64bit-primitive) should be ignored in Pulsar source code since Pulsar required 64-bit JVM, #10311.
### Anything else?
_No response_
### Are you willing to submit a PR?
- [ ] I'm willing to submit a PR!
Contributor guide
Research direction
Start with the SpotBugs omitVisitors configuration changed in #24243 and enable the listed detectors one at a time. Run the SpotBugs checks to identify affected Pulsar code, then inspect each finding and determine whether it requires a fix or a justified exclusion. Done means the selected checks are enabled and their findings are resolved or documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100