Wrong Warning - Dereferencing possible null pointer
- Dominant language
- Java
- Stars
- 3.1k
- Forks
- 935
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 17
Description
### Apache NetBeans version
Apache NetBeans 18
### What happened
NetBeans warns about dereferencing possible null pointer where I'm somewhat sure that no NPE can happen at all, because null-checks are available already. But the results of those are stored as additional booleans and NetBeans seems unable to take those results into account. There's some [old bug report](https://bz.apache.org/netbeans/show_bug.cgi?id=223031) with similar problems in the archived Bugzilla.
### How to reproduce
The following code triggers the warning:
```java
Supplier s = (Supplier) li.getFullEntity();
boolean hasSupp = s != null;
boolean hasAllow = allowListIf != null;
if (hasSupp && (!hasAllow || allowListIf.contains(s.id)))
{
ret.add(s);
}
```
OTOH, replacing the booleans with the direct null checks removes the warning:
```java
Supplier s = (Supplier) li.getFullEntity();
boolean hasSupp = s != null;
boolean hasAllow = allowListIf != null;
if ((s != null) && (!(allowListIf != null) || allowListIf.contains(s.id)))
{
ret.add(s);
}
```
### Did this work correctly in an earlier version?
No / Don't know
### Operating System
Windows 10 64 Bit 22H2 Build 19045.3086
### JDK
openjdk version "17.0.7" 2023-04-18, OpenJDK Runtime Environment Temurin-17.0.7+7 (build 17.0.7+7), OpenJDK 64-Bit Server VM Temurin-17.0.7+7 (build 17.0.7+7, mixed mode, sharing)
### Apache NetBeans packaging
Apache NetBeans provided installer
### Anything else
_No response_
### Are you willing to submit a pull request?
No
Contributor guide
Research direction
Reproduce the warning in NetBeans 18 using the Java snippet in the issue, then locate the null-pointer analysis that handles the condition. Check how null checks stored in boolean variables are tracked; done means the equivalent boolean-alias example is no longer falsely warned while genuinely unsafe dereferences remain reported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100