typetools / typetools/checker-framework

False negative for postconditions with `this` or `#n` in their expression

Open
#6,291 0 comments 0 reactions 1 assignee View on GitHub

@smillst is already working on this.

Since Nov 15, 2023.

False Negative (missing warning or unsoundness)
Dominant language
Java
Stars
1.1k
Forks
440
Avg merge
1d 12h
Merged PRs (30d)
134

Description

Commit d70dd7436fa9a6706db40be85978ac4dd04d2a18 introduces a false negative, in its use of CFAbstractStore.insertValuePermitNondeterministic(). Consider this test case:

import java.util.Optional;

class PureGetterTest2 {

  Optional<String> otherOptional() {
    if (Math.random() < 0.5) {
      return Optional.ofNullable(null);
    } else {
      return Optional.of("hello world");
    }
  }

  void foo() {
    if (otherOptional().isPresent()) {
      // BUG: no "method.invocation" error is issued here.
      otherOptional().get();
    }
  }
}

In a postcondition like @EnsuresPresent("field.method()"), it is correct to permit method() in the expression even if it is not @Deterministic. However, in a postcondition like @EnsuresPresent("#1.method()"), it should not be permitted to substitute in an argument that is not @Deterministic.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.