Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mernst opened this issue Nov 11, 2023 · 0 comments
Open

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

mernst opened this issue Nov 11, 2023 · 0 comments

Comments

@mernst
Copy link
Member

mernst commented Nov 11, 2023

Commit d70dd74 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants