Bug 548551 - [null] @Nullable declaration ignored rather than overriding flow analysis
Summary: [null] @Nullable declaration ignored rather than overriding flow analysis
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.13   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-06-23 04:12 EDT by Ed Willink CLA
Modified: 2022-06-01 06:33 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ed Willink CLA 2019-06-23 04:12:15 EDT
In the following example in which the toString() method is coded to avoid a crash if invoked prematurely by the debugger during construction:

package bug;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;

public class NonNullBug
{
	protected final @NonNull String s;

	public NonNullBug(@NonNull String s) {
		this.s = s;
	}

	@Override
	public String toString() {
		@Nullable String s2 = s;
		return s2 != null ? s2.toString() : super.toString();
	}
}

JDT gives:

  Redundant null check: The variable s2 cannot be null at this location

on the return line. This is incorrrct because the user has declared that s2 can be null. Rather there should be a warning on the s2 = s declaration that s2 cannot be null providing an opportunity for the user to apply a suppress null warning annotation to allow the above code to function as intended without any warnings.
Comment 1 Till Brychcy CLA 2019-06-24 03:38:09 EDT
Use org.eclipse.jdt.annotation.Checks.isNull(Object)
Comment 2 Eclipse Genie CLA 2022-05-31 13:04:52 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 3 Ed Willink CLA 2022-06-01 06:33:10 EDT
The original problem has not been addressed by comment #1.

Rather a suggestion to code differently is given. Alternative code will indeed often avoid a bug, but the bug still needs to be addressed.

The suggested alternative has stronger org.eclipse.jdt.annotation dependency, requiring a mandatory rather than optional bundle.