Skip to content

"no such method" message when method exists but is private #4858

@mernst

Description

@mernst

The Checker Framework issues a "no such method" message when a method exists but is not visible.
It would be better to permit private methods to be used in specifications.

Running the Nullness Checker on the below file yields

NoSuchMethodVisibility.java:15: error: [flowexpr.parse.error] cannot parse the expression [error for expression: privateMap(); error: Invalid 'privateMap' because no such method]
  public boolean isMapped(final String name) {
                 ^
1 error
import java.util.Map;
import org.checkerframework.checker.nullness.qual.EnsuresKeyForIf;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.dataflow.qual.Pure;

@SuppressWarnings("contracts.conditional.postcondition")
public final class NoSuchMethodVisibility {

  @Pure
  private @Nullable Map<String, Integer> privateMap() {
    return null;
  }

  @EnsuresKeyForIf(expression = "#1", map = "privateMap()", result = true)
  public boolean isMapped(final String name) {
    return true;
  }

  @Pure
  public @Nullable Map<String, Integer> publicMap() {
    return null;
  }

  @EnsuresKeyForIf(expression = "#1", map = "publicMap()", result = true)
  public boolean isMapped2(final String name) {
    return true;
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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