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

Key: IDEABKL-5052
Type: New Feature New Feature
Status: Open Open
Priority: Normal Normal
Assignee: Alexey Kudravtsev
Reporter: Derek Foster
Votes: 0
Watchers: 0
Available Workflow Actions

Mark as Stalled
Operations

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

Want inspections: "Field/Variable/Parameter could be @NotNull", etc.

Created: 20 Dec 06 00:01   Updated: 21 Feb 07 17:58
Component/s: Code Analysis. Inspection, Editor. Error Highlighting, Editor. Intention Actions
Affects Version/s: None
Fix Version/s: None

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

Build: 6,107
Severity: High


 Description  « Hide
In a situation like the following:
class Foo
{
final String bar;
Foo(@NotNull baz, String foon) { bar = baz; final String qux = quux(); String spork = quux(); spork = new String(); foon.contains("abc"); }

final @NotNull String quux() {return "Q"};

}

I would like Idea to suggest to me that the variable 'bar' could be declared @NotNull (because it is final and initialized from a @NotNull value).
Similarly, I think that Idea could determine that qux and spork could be declared @NotNull (because they are only assigned to from values that are known to be not null, or declared as @NotNull).
Similarly, I think that Idea could determine that foon could be declared @NotNull (because a method is called on it with no check for null beforehand... if it were null, a NullPointerException would result).

I would like to have inspections to check for these cases and intentions to add the @NotNull keyword.

I would also like to have Idea able to do similar things with @Nullable. For instance, if null, or an a @Nullable value is ever assigned to a variable or field, then Idea should be able to suggest that the variable or field be declared @Nullable.



 All   Comments   Work Log   Change History      Sort Order:
Derek Foster - 20 Dec 06 00:08
Additionally, if a method (especially a simple getter, but any method really) and any super/subclass methods with the same signature can only return a non-null value, then Idea should suggest adding @NotNull to the method declaration.