typetools / typetools/checker-framework

Allow private fields in preconditions even when the field isn't accessible at call sites.

Open
#1,951 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
1.1k
Forks
440
Avg merge
1d 12h
Merged PRs (30d)
134

Description

This is a follow-up to #1582.

The following example is similar to the original bug, where a private field referenced by @RequiresNonNull is not visible across compilation boundaries.

Repro:

package foo;

import org.checkerframework.checker.initialization.qual.UnknownInitialization;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.nullness.qual.RequiresNonNull;

import java.util.function.Supplier;

public class Foo {
  @Nullable private Supplier<String> s;

  @RequiresNonNull("s")
  public String f(@UnknownInitialization Foo this) {
    return s.get();
  }
}
package mainrepropkg;

import foo.Foo;
import java.util.Optional;

public class FlowExprParseError {

  private String t(Foo foo, String type) {
    return Optional.ofNullable(foo.f()).orElse("");
  }
}
  1. Create an interface jar for Foo using this tool distributed with Bazel, or just download this copy of the jar I used: https://github.com/typetools/checker-framework/files/1934273/lib-interface.zip
$ ./checker-framework-2.5.0/checker/bin/javac foo/Foo.java 
$ jar cvf lib.jar foo/Foo.class 
$ ijar lib.jar
$ javap -p -cp lib.jar foo.Foo
Compiled from "Foo.java"
public class foo.Foo {
  private java.util.function.Supplier<java.lang.String> s;
  public foo.Foo();
  public java.lang.String f();
}
$ javap -p -cp lib-interface.jar foo.Foo
public class foo.Foo {
  public foo.Foo();
  public java.lang.String f();
}
  1. Run the nullness checker on FlowExprParseError.java with foo.Foo on the classpath, observe a flowexpr.parse.error. Based on #1582 I expected a flowexpr.parse.postcondition.error.
$ ./checker-framework-2.5.0/checker/bin/javac -sourcepath : -cp lib-interface.jar -processor Nullness FlowExprParseError.java
FlowExprParseError.java:9: error: [flowexpr.parse.error] cannot parse the expression 's' because identifier not found
    return Optional.ofNullable(foo.f()).orElse("");
                                    ^
1 error

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.

Research direction

Reproduce the issue with the provided Foo.java, FlowExprParseError.java, interface JAR, and Nullness javac command. Start by tracing handling of @RequiresNonNull expressions when the referenced private field is absent from the interface JAR. Done means the cross-boundary call reports the expected flowexpr.parse.postcondition.error instead of flowexpr.parse.error.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.