Skip to content

False positive with dereference.of.nullable #6760

@mahfouz72

Description

@mahfouz72

The Checker Framework is flagging a possible null dereference in the below code snippet, where lambdaParameters.peek() is being checked for null before it is dereferenced. This seems to be a false positive, as the code should not cause a null dereference.

Code:

while (lambdaParameters.peek() != null
        && ast.equals(lambdaParameters.peek().enclosingLambda)) {

    final Optional<LambdaParameterDetails> unusedLambdaParameter =
            Optional.ofNullable(lambdaParameters.peek())
                    .filter(parameter -> !parameter.isUsed())
                    .filter(parameter -> !"_".equals(parameter.getName()));

    ....
}

Output:

New surviving error(s) found:

  <checkerFrameworkError unstable="false">
    <fileName>src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/UnusedLambdaParameterShouldBeUnnamedCheck.java</fileName>
    <specifier>dereference.of.nullable</specifier>
    <message>dereference of possibly-null reference lambdaParameters.peek()</message>
    <lineContent>&amp;&amp; ast.equals(lambdaParameters.peek().enclosingLambda)) {</lineContent>
  </checkerFrameworkError>

Expectations:

This issue appears to be a false positive because lambdaParameters.peek() is explicitly checked for nullity before any dereferencing occurs. The error persists even though the code logic should prevent a null dereference.


Build tool: maven
checker version: 3.46.0

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions