Details
-
Type:
Bug Detection
-
Status: Active
-
Resolution: Unresolved
-
Message:
-
Default Severity:Minor
-
Impact:Low
-
Likelihood:Low
-
Default Quality Profiles:Sonar way
-
Covered Languages:C, C++, Java, Objective-C
-
Remediation Function:Constant/Issue
-
Constant Cost:15min
-
Analysis Scope:Main Sources
-
Implementation details:
-
CERT:EXP01-J.
-
CWE:CWE-476
-
FindBugs:NP_NONNULL_.*, NP_NULL_PARAM_DEREF.*,NP_STORE_INTO_NONNULL_FIELD,NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE
Description
Fields, parameters and return values marked @NotNull, @NonNull, or @Nonnull are assumed to have non-null values and are not typically null-checked before use. Therefore setting one of these values to null, or failing to set such a class field in a constructor, could cause {{NullPointerException}}s at runtime.
Noncompliant Code Example
public class MainClass { @Nonnull private String primary; private String secondary; public MainClass(String color) { if (color != null) { secondary = null; } primary = color; // Noncompliant; "primary" is Nonnull but could be set to null here } public MainClass() { // Noncompliant; "primary" Nonnull" but is not initialized } @Nonnull public String indirectMix() { String mix = null; return mix; // Noncompliant; return value is Nonnull, but null is returned.}} }
See
- MITRE CWE-476 - NULL Pointer Dereference
- CERT, EXP01-J. - Do not use a null in a case where an object is required
Attachments
Issue Links
- is implemented by
-
CPP-1521 C rule: "nonnull" pointers should not be set to null
-
- Closed
-
-
CPP-1677 C++ Rule: "nonnull" pointers should not be set to null
-
- Closed
-
-
CPP-2312 Add 12 rules for Objective-C based on symbolic execution
-
- Closed
-
-
SONARJAVA-1563 Rule S2637: "@NonNull" values should not be set to null
-
- Closed
-
- is related to
-
CPP-2710 S2637: sync rule implementation with the RSPEC
-
- Closed
-
-
SONARJAVA-1648 NPE on S2637 on void method annotated with @Nonnull using empty return statement
-
- Closed
-
-
CPP-2402 Improve S2637 RSPEC to reflect the rule implementation
-
- Closed
-
-
SONARJAVA-3695 FP in S2637 when the field is initialized in the setter
-
- Open
-
-
SONARJAVA-4026 FP in S2637 with user defined preconditions
-
- Open
-
-
SONARJAVA-4201 S2637 should not raise on methods returning a non null value from a ternary operator
-
- Open
-
-
SONARJAVA-1681 FP on S2637: Usages of "this" for fields
-
- Closed
-
-
SONARJAVA-1977 FP on S2637: Default no-arg constructors for JPA entities
-
- Closed
-
-
SONARJAVA-1978 FP on S2637: variable with initializers
-
- Closed
-
-
SONARJAVA-4025 FP in S2637 with non-null primitive field not initialized
-
- Closed
-
1.
|
C-Family: "nonnull" pointers should not be set to null | RSPEC-3724 |
|
Active | Unassigned |