SonarQube failing to recognize ObjectUtils.isEmpty()

  • Operating system: Windows 11
  • SonarQube for IntelliJ plugin version: 10.22.0.81244
  • IntelliJ version: IntelliJ IDEA 2024.3.5
  • Programming language you’re coding in: Java
  • Is connected mode used: No

SonarQube is incorrectly recognizing a rule java:S2259 in my code, because it does not know that ObjectUtils.isEmpty(mockObject) checks whether the ‘mockObject’ is null. It thinks that mockObject could still be null, even after the ObjectUtils.isEmpty check.

Hi,

Welcome to the community!

Could we get a reproducer code sample where the rule is wrongly raising an issue?

 
Thx,
Ann

Hi G Ann,

Please excuse me, I sent the wrong documentation link. It’s the isEmpty() method from here: Apache Commons Lang 3.11 API

I’m still working on getting a code snippet for you; I’m having trouble reproducing the issue in a test class. I’ll get back to you on Monday.

Thanks,
Daniel