eclipse-jdt / eclipse-jdt/eclipse.jdt.core

Correlation-aware null analysis

Open
#3,088 2 comments 0 reactions 0 assignees View on GitHub
duplicate null
Dominant language
Java
Stars
237
Forks
195
Avg merge
1d 10h
Merged PRs (30d)
49

Description

Continued from https://bugs.eclipse.org/bugs/show_bug.cgi?id=538421:

The current null analysis in ECJ does not recognize a certain class of patterns where nullness of one variable could theoretically be inferred more precisely due to correlation to another variable.

Simple example:

```java
String m(boolean f) {
String s = null;
if (f)
s = "good";
// more stuff here
if (f)
return s.toUpperCase(); // expect no warning
return "";
}
```
Our current implementation has a very compact representation of nullness information, consisting basically of 6 bits per variable (at each point in the flow). This fixed-size representation is not able to capture any correlation information concerning an unknown number of other variables. Hence in the above example at the marked location, ECJ can only see that "s" can be either null or nonnull on some paths and it will raise a warning against the dereference.

This RFE captures the request to implement a new null analysis that would capture correlation information in order to 'understand' that examples like the above are indeed null-safe.

I'm saying "new null analysis", because I don't believe that extending the current implementation to include correlation analysis is a viable strategy. Aside from matters of code complexity, it should be kept in mind that the current analysis has been designed for small footprint (mem and cpu), good enough to be invoked on every key stroke as you type in a Java editor. The new null analysis will probably not fulfill this criterion.

This could imply, that in addition to a new analysis, we'd also need new infrastructure to invoke this analysis at selected points in time.

I should mention that no-one in the JDT team currently has the time to even start working on a detailed design of this feature, not to mention implement it.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing ECJ's current null analysis and the linked Eclipse bug 538421; the issue names no source files or tests. A complete contribution would require a detailed design for correlation-aware analysis, likely including when the new analysis is invoked, followed by implementation and validation of the example pattern.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.