What rule is raising this issue? The id will be something like java:S111. Also, can you upgrade to the latest version, SonarQube 9.8, and see if this is replicable?
Thank you for reporting this issue. Indeed, this looks like a false positive.
Unfortunately, I have not been able to reproduce the issue on SonarCloud or SonarQube based on the first example provided in the initial post. Could you provide a stand-alone compilable reproducer, which triggers this behavior? Optionally, I can open a private channel for you to share such a reproducer if you cannot make it work without including private code.