Movatterモバイル変換


[0]ホーム

URL:


CodeQL documentation
CodeQL resources

Dereferenced expression may be null

ID: java/dereferenced-expr-may-be-nullKind: problemSecurity severity: Severity: warningPrecision: highTags:   - quality   - reliability   - correctness   - exceptions   - external/cwe/cwe-476Query suites:   - java-code-quality.qls   - java-security-and-quality.qls

Click to see the query in the CodeQL repository

Dereferencing anull value leads to aNullPointerException.

An expression may be implicitly dereferenced if its type is a boxed primitive type, and it occurs in a context in which implicit unboxing occurs.

Recommendation

Ensure that the expression does not have anull value when it is dereferenced. Use boxed types as appropriate to hold values that are potentiallynull.

Example

In the following example implicit unboxing can cause aNullPointerException ifhelper isnull.

publicintgetID(){returnhelper==null?null:helper.getID();}

If the method is intended to returnnull, the return type should be changed toInteger.

References


[8]ページ先頭

©2009-2025 Movatter.jp