History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: IDEABKL-2949
Type: New Feature New Feature
Status: Open Open
Priority: Major Major
Assignee: Maxim Shafirov
Reporter: Gibson
Votes: 0
Watchers: 3
Available Workflow Actions

Mark as Stalled
Operations

If you were logged in you would be able to see more operations.
IDEA: Backlog

Kind of @NotNull for specifying non-nullnes of collection or array elements

Created: 19 May 05 18:14   Updated: 12 Mar 07 18:39
Component/s: Code Analysis. Inspection
Affects Version/s: None
Fix Version/s: None

Original Estimate: Unknown Remaining Estimate: Unknown Time Spent: Unknown

Build: 3,339
Severity: Medium


 Description  « Hide
So far the @NotNull annotation can be applied to pretty much any element. And it is an inspection error to assign an element of type @Nullable (or maybe unknown type, see http://www.jetbrains.net/jira/browse/IDEA-2087 ).

But what about the situation where we assign a value to a variable where the assignment doesn't come from a method return value, a field or a local variable?

void doTest() {
// We have flagged the collection, but not its contents
@NotNull Collection<String> c = new ArrayList<String> ();
c.add ("Test");
c.add (null); // Oops

// How can we be sure that all the elements of c are not null?
for (@NotNull String s : c) { // Not flagged doTest2 (s); }
}

void doTest2 (@NotNull String s) {
// Not flagged, and I don't test for null
if (s.equals ("Test")) { // ... }
}

Do we maybe need a subsidiary annotation, something like @IteratorNeverReturnsNullInAnyCaseWhatsoever (or maybe something a bit shorter ?

OK, this isn't really a bug, but I was just playing around and I thought I would submit this case for consideration.



 All   Comments   Work Log   Change History      Sort Order: