GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • CodeQL documentation
  • CodeQL overview
  • Writing CodeQL queries
  • CodeQL language guides
  • QL language reference
  • CodeQL standard-libraries
  • CodeQL query help
  • CodeQL repository
  • QL publications
  • CodeQL query help for C and C++
  • CodeQL query help for C#
  • CodeQL query help for GitHub Actions
  • CodeQL query help for Go
  • CodeQL query help for Java and Kotlin

This view

  • Original page
  • New address

GeezerVison is showing codeql.github.com — Dereferenced expression may be null — CodeQL query help documentation

Dereferenced expression may be null¶

ID: java/dereferenced-expr-may-be-null
Kind: problem
Security severity: 
Severity: warning
Precision: high
Tags:
   - quality
   - reliability
   - correctness
   - exceptions
   - external/cwe/cwe-476
Query suites:
   - java-code-quality.qls
   - java-security-and-quality.qls

Click to see the query in the CodeQL repository

Dereferencing a null value leads to a NullPointerException.

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 a null value when it is dereferenced. Use boxed types as appropriate to hold values that are potentially null.

Example¶

In the following example implicit unboxing can cause a NullPointerException if helper is null.

public int getID() {
    return helper == null ? null : helper.getID();
}

If the method is intended to return null, the return type should be changed to Integer.

References¶

  • The Java Tutorials: Autoboxing and Unboxing.

  • Common Weakness Enumeration: CWE-476.

  • © GitHub, Inc.
  • Terms
  • Privacy
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.