Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
15 changed files
with
264 additions
and
307 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class Issue354 { | ||
|
||
String a; | ||
|
||
{ | ||
Object o = | ||
new Object() { | ||
@Override | ||
public String toString() { | ||
// :: error: (dereference.of.nullable) | ||
return a.toString(); | ||
} | ||
}.toString(); | ||
|
||
// This is needed to avoid the initialization.fields.uninitialized warning. | ||
// The NPE still occurs | ||
a = ""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// @below-java9-jdk-skip-test | ||
class Issue3408 { | ||
final String foo; | ||
|
||
String getFoo() { | ||
return foo; | ||
} | ||
|
||
Issue3408() { | ||
var anon = | ||
new Object() { | ||
String bar() { | ||
// :: error: (method.invocation.invalid) | ||
return Issue3408.this.getFoo().substring(1); | ||
} | ||
}; | ||
anon.bar(); // / WHOOPS... NPE, `getFoo()` returns `foo` which is still null | ||
this.foo = "Hello world"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
// @skip-test | ||
// Test case for Issue 352: | ||
// https://github.com/typetools/checker-framework/issues/352 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import org.checkerframework.checker.tainting.qual.*; | ||
|
||
public class Issue3561 { | ||
void outerMethod(@Untainted Issue3561 this) {} | ||
|
||
class Inner { | ||
void innerMethod(@Untainted Issue3561.@Untainted Inner this) { | ||
Issue3561.this.outerMethod(); | ||
} | ||
|
||
void innerMethod2(@Tainted Issue3561.@Untainted Inner this) { | ||
// :: error: (method.invocation.invalid) | ||
Issue3561.this.outerMethod(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.