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

Implicit "this" passed through non-static inner class loses @UnderInitialization #409

Open
GoogleCodeExporter opened this issue Jul 3, 2015 · 5 comments

Comments

@GoogleCodeExporter
Copy link

The following code fails at runtime with an NPE, but does not cause an error in 
the checker framework. I'm guessing, but I believe this is because when I call 
p.call(), the "this" which is passed through to the inner class loses it's 
@UnderInitialization.

class Callback {
  static interface Proc {
    void call();
  }

  Proc p;

  class MyProc implements Proc {
    @Override
    public void call() {
      doStuff();
    }
  }

  String foo;

  Callback() {
    p = new MyProc();
    p.call();
    foo = "hello";
  }

  void doStuff() {
    System.out.println(foo.toLowerCase());
  }

  public static void main(String[] args) {
    new Callback();
  }
}

Original issue reported on code.google.com by eatnumb...@google.com on 9 Mar 2015 at 8:41

@mernst
Copy link
Member

mernst commented Feb 9, 2018

I have created a smaller version of this test case and committed it as checker/tests/nullness/Issue409.java.

@mernst mernst modified the milestones: Medium, High Feb 9, 2018
@wmdietl
Copy link
Member

wmdietl commented Feb 9, 2018

There already is a checker/tests/nullness/init/Issue409.java. Should the smaller test case also go into checker/tests/nullness/init/?

@mernst
Copy link
Member

mernst commented Feb 9, 2018

Thanks for pointing that out! I have moved the smaller test case, replacing the larger one.
So. the test can now be found in checker/tests/nullness/init/Issue409.java.

smillst added a commit that referenced this issue Sep 15, 2020
This pull request corrects the type of both implicit and explicit `this` references by correctly computing the enclosing type of `this`.

This pull request fixes two kinds of bugs: 
1. The type of `Outer.this` when used in an inner class.   (Issues #352, #2208, and #3561.)
2. For the Initialization Checker, the type of `Outer.this` when used in an anonymous class declared in a constructor. (Issues #354, part of #904, and #3408)

#409 (and other duplicate issues) is a related bug in the Initialization Checker, but isn't fixed by this PR.

Closes #352, closes #354, closes #2208, closes #3266, closes #3408 and closes #3561.
mernst pushed a commit to mernst/checker-framework that referenced this issue Feb 28, 2023
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

3 participants