Fix nullness detection on exception variable

This commit is contained in:
Alexey Andreev 2017-02-25 19:48:44 +03:00
parent 6ef08ae709
commit a94686ddf6
4 changed files with 29 additions and 1 deletions

View File

@ -203,7 +203,7 @@ class NullnessInformationBuilder {
currentState = new State();
if (block.getExceptionVariable() != null) {
notNullVariables.set(block.getIndex());
notNullVariables.set(block.getExceptionVariable().getIndex());
}
currentBlock = block;

View File

@ -80,6 +80,11 @@ public class NullnessAnalysisTest {
test();
}
@Test
public void exception() {
test();
}
private void test() {
String baseName = "model/analysis/nullness/" + name.getMethodName();
String originalResourceName = baseName + ".original.txt";

View File

@ -0,0 +1,12 @@
var @this as this
$start
@str := invokeStatic `Foo.getData()Ljava/lang/String;`
@n := invokeStatic `java.lang.Integer.parseInt(Ljava/lang/String;)I` @str
return @n
catch java.lang.RuntimeException goto $handle
$handle
@e := exception
@m := invoke `java.lang.Throwable.getMessage()Ljava/lang/String;` @e
@z := invoke `java.lang.String.length()I` @m
@m_1 := nullCheck @m
return @z

View File

@ -0,0 +1,11 @@
var @this as this
$start
@str := invokeStatic `Foo.getData()Ljava/lang/String;`
@n := invokeStatic `java.lang.Integer.parseInt(Ljava/lang/String;)I` @str
return @n
catch java.lang.RuntimeException goto $handle
$handle
@e := exception
@m := invoke `java.lang.Throwable.getMessage()Ljava/lang/String;` @e
@z := invoke `java.lang.String.length()I` @m
return @z