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

Handling of annotation defaulting in stubs between 3.4.0 and 3.4.1 #3597

Closed
cushon opened this issue Aug 15, 2020 · 2 comments · Fixed by #3599
Closed

Handling of annotation defaulting in stubs between 3.4.0 and 3.4.1 #3597

cushon opened this issue Aug 15, 2020 · 2 comments · Fixed by #3599
Assignees

Comments

@cushon
Copy link
Contributor

cushon commented Aug 15, 2020

Prior to 3.4.0, a stub file without annotations could be used to override annotations present in the corresponding classpath dependency (in the example below, the stub file for p.B#f has an implicitly non-null return type, which overrides the nullable type in the source file).

Was this change deliberate? The most likely culprit I see is 3ce0ab5. The repro doesn't use -Ainfer, and passing -AmergeStubsWithSource has no effect. If this change was deliberate, is there a way to restore the previous behaviour?

=== stubs/p.astub
package p;

import org.checkerframework.checker.nullness.qual.Nullable;

class B {
  Object f();
}
=== p/B.java
package p;

import org.checkerframework.checker.nullness.qual.Nullable;

class B {
  @Nullable
  Object f() {
    return new Object();
  }
}
=== p/A.java
package p;

class A {
  void f() {
    System.err.println(new B().f().toString());
  }
}

Compiling with p.B on the classpath, and with its corresponding stub, produces a diagnostic with 3.4.1 but not with 3.4.0:

./checker-framework-3.4.0/checker/bin/javac p/B.java
./checker-framework-3.4.0/checker/bin/javac -Astubs=stubs -processor Nullness -sourcepath : -cp . p/A.java 
./checker-framework-3.4.1/checker/bin/javac -Astubs=stubs -processor Nullness -sourcepath : -cp . p/A.java 
p/A.java:5: error: [dereference.of.nullable] dereference of possibly-null reference new B().f()
    System.err.println(new B().f().toString());
                                ^
1 error
@kelloggm kelloggm self-assigned this Aug 17, 2020
@kelloggm
Copy link
Contributor

I've confirmed and reproduced this bug. There is a failing test case here: https://github.com/kelloggm/checker-framework/tree/stub-overwrite-bug

The bug is caused by 3ce0ab5, which I confirmed by running this test on that commit and the one before it. I'll look into the problem.

@kelloggm
Copy link
Contributor

kelloggm commented Aug 17, 2020

@cushon, thanks for finding this bug and building the test case. This led me to find two related problems, which are all (hopefully) fixed (along with this one) in #3599.

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