File tree Expand file tree Collapse file tree 2 files changed +18
-14
lines changed
codeql-custom-queries-java Expand file tree Collapse file tree 2 files changed +18
-14
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Finds `throw` statements which throw the `null` literal, i.e. `throw null;`.
3
+ * While this does produce a `NullPointerException` (as probably desired)
4
+ * it is rather obscure and misuses the `null` check of the `throw` statement.
5
+ * For clarity it would be better to explicitly create a `NullPointerException`
6
+ * and possibly provide a meaningful message to its constructor.
7
+ *
8
+ * See also Error Prone pattern [ThrowNull](https://errorprone.info/bugpattern/ThrowNull).
9
+ *
10
+ * @kind problem
11
+ */
12
+
13
+ import java
14
+
15
+ from ThrowStmt throwStmt
16
+ where
17
+ throwStmt .getExpr ( ) instanceof NullLiteral
18
+ select throwStmt , "Should use `throw new NullPointerException(...)` instead"
You can’t perform that action at this time.
0 commit comments