mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 13:15:25 +07:00
ObviousNullCheckInspection: support assertNull-like methods
Fixes IDEA-174782 "Useless null checks": highlight always-(not-)null arguments to assertNull/assertNotNull
This commit is contained in:
@@ -6,9 +6,12 @@ abstract class ObviousNullCheck {
|
||||
|
||||
abstract String getBar();
|
||||
|
||||
void test() {
|
||||
void test(String param) {
|
||||
assertNotNull(<warning descr="Useless null-check: a value of primitive type is never null">5 + 6</warning>);
|
||||
|
||||
assertNull("Null!", param);
|
||||
assertNull(param, <warning descr="Null-check will always fail: literal is never null">"Null!"</warning>);
|
||||
|
||||
Objects.requireNonNull(null);
|
||||
Objects.requireNonNull(<warning descr="Useless null-check: literal is never null">"xyz"</warning>, "xyz");
|
||||
Objects.requireNonNull((<warning descr="Useless null-check: concatenation is never null">getFoo() + getBar()</warning>));
|
||||
@@ -27,4 +30,10 @@ abstract class ObviousNullCheck {
|
||||
static void assertNotNull(Object obj) {
|
||||
if(obj == null) throw new NullPointerException();
|
||||
}
|
||||
|
||||
@Contract(value="_,!null -> fail", pure=true)
|
||||
static void assertNull(String msg, Object obj) {
|
||||
if(obj != null) throw new NullPointerException(msg);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user