2023-05-03 11:06:20 +02:00
|
|
|
== Why is this an issue?
|
|
|
|
|
2023-10-23 14:29:59 +02:00
|
|
|
A reference to `null` should never be dereferenced/accessed.
|
|
|
|
Doing so will cause a `NullPointerException` to be thrown.
|
|
|
|
At best, such an exception will cause abrupt program termination.
|
|
|
|
At worst, it could expose debugging information that would be useful to an attacker,
|
|
|
|
or it could allow an attacker to bypass security measures.
|
|
|
|
|
|
|
|
Note that when they are present, this rule takes advantage of nullability annotations,
|
|
|
|
like `@CheckForNull` or `@Nonnull`, defined in https://jcp.org/en/jsr/detail?id=305[JSR-305]
|
|
|
|
to understand which values can be null or not.
|
|
|
|
`@Nonnull` will be ignored if used on the parameter of the `equals` method, which by contract should always work with null.
|
|
|
|
|
|
|
|
== How to fix it
|
|
|
|
|
|
|
|
=== Code examples
|
|
|
|
|
|
|
|
==== Noncompliant code example
|
|
|
|
|
|
|
|
include::noncompliant-code.adoc[]
|
|
|
|
|
|
|
|
==== Compliant solution
|
|
|
|
|
|
|
|
include::compliant-code.adoc[]
|
2020-06-30 12:48:07 +02:00
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
== Resources
|
2021-09-21 15:40:35 +02:00
|
|
|
|
2024-01-15 17:15:56 +01:00
|
|
|
* CWE - https://cwe.mitre.org/data/definitions/476[CWE-476 - NULL Pointer Dereference]
|
2023-10-23 14:29:59 +02:00
|
|
|
* CERT, EXP34-C. - https://wiki.sei.cmu.edu/confluence/x/QdcxBQ[Do not dereference null pointers]
|
|
|
|
* CERT, EXP01-J. - https://wiki.sei.cmu.edu/confluence/x/aDdGBQ[Do not use a null in a case where an object is required]
|
2021-06-02 20:44:38 +02:00
|
|
|
|
2021-06-03 09:05:38 +02:00
|
|
|
ifdef::env-github,rspecator-view[]
|
2021-09-20 15:38:42 +02:00
|
|
|
|
|
|
|
'''
|
|
|
|
== Implementation Specification
|
|
|
|
(visible only on this page)
|
|
|
|
|
2023-05-25 14:18:12 +02:00
|
|
|
=== Message
|
|
|
|
|
|
|
|
* 'XXXX' is nullable here and method 'YYY' don't accept nullable argument
|
|
|
|
* NullPointerException might be thrown as 'XXXX' is nullable here
|
|
|
|
|
2021-09-20 15:38:42 +02:00
|
|
|
|
|
|
|
include::../highlighting.adoc[]
|
|
|
|
|
2021-06-08 15:52:13 +02:00
|
|
|
'''
|
2021-06-02 20:44:38 +02:00
|
|
|
== Comments And Links
|
|
|
|
(visible only on this page)
|
|
|
|
|
2023-05-25 14:18:12 +02:00
|
|
|
include::../comments-and-links.adoc[]
|
|
|
|
|
2021-06-03 09:05:38 +02:00
|
|
|
endif::env-github,rspecator-view[]
|