-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This PR fixes both issue #3249 and issue #1727, by adapting the CFG in the following way: If the loop condition is checked to be a constant true (according to the same logic in javac flow analysis), then the loop condition does not have an else-branch, i.e. the block holding the loop condition is directly followed by the one holding the loop entry, instead of followed by a conditional block. Fixes #1727 and Fixes #3249`
- Loading branch information
Showing
4 changed files
with
147 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Test case for Issue 1727: | ||
// https://github.com/typetools/checker-framework/issues/1727 | ||
|
||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
class B {} | ||
|
||
public class Issue1727 { | ||
|
||
private B foo() { | ||
// Default type for local variable b is @UnknownInitialization @Nullable | ||
B b; | ||
|
||
while (true) { | ||
B op = getB(); | ||
if (op == null) { | ||
b = new B(); | ||
break; | ||
} else { | ||
b = op; | ||
break; | ||
} | ||
} | ||
|
||
return b; | ||
} | ||
|
||
private @Nullable B getB() { | ||
return new B(); | ||
} | ||
} |
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,64 @@ | ||
// Test case for Issue 3249: | ||
// https://github.com/typetools/checker-framework/issues/3249 | ||
|
||
public class Issue3249 { | ||
|
||
private final double field; | ||
|
||
Issue3249() { | ||
double local; | ||
while (true) { | ||
local = 1; | ||
break; | ||
} | ||
field = local; | ||
} | ||
|
||
Issue3249(int x) { | ||
double local; | ||
while (!false) { | ||
local = 1; | ||
break; | ||
} | ||
field = local; | ||
} | ||
|
||
Issue3249(float x) { | ||
double local; | ||
while (true || x > 0) { | ||
local = 1; | ||
break; | ||
} | ||
field = local; | ||
} | ||
|
||
Issue3249(double x) { | ||
double local; | ||
while (!false && true && !false) { | ||
local = 1; | ||
break; | ||
} | ||
field = local; | ||
} | ||
|
||
// Case for while conditions that contain final variables, | ||
// which are treated as constant. | ||
Issue3249(String x) { | ||
double local; | ||
final int i = 1; | ||
while ((i > 0) && !false) { | ||
local = 1; | ||
break; | ||
} | ||
field = local; | ||
} | ||
|
||
Issue3249(boolean x) { | ||
double local; | ||
while (6 > 4) { | ||
local = 1; | ||
break; | ||
} | ||
field = local; | ||
} | ||
} |
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