diff --git a/core/src/main/java/org/teavm/model/analysis/NullnessInformationBuilder.java b/core/src/main/java/org/teavm/model/analysis/NullnessInformationBuilder.java index a48a6e3d5..eb3612e5b 100644 --- a/core/src/main/java/org/teavm/model/analysis/NullnessInformationBuilder.java +++ b/core/src/main/java/org/teavm/model/analysis/NullnessInformationBuilder.java @@ -203,7 +203,7 @@ class NullnessInformationBuilder { currentState = new State(); if (block.getExceptionVariable() != null) { - notNullVariables.set(block.getIndex()); + notNullVariables.set(block.getExceptionVariable().getIndex()); } currentBlock = block; diff --git a/core/src/test/java/org/teavm/model/analysis/test/NullnessAnalysisTest.java b/core/src/test/java/org/teavm/model/analysis/test/NullnessAnalysisTest.java index df59cbcd6..9592477d9 100644 --- a/core/src/test/java/org/teavm/model/analysis/test/NullnessAnalysisTest.java +++ b/core/src/test/java/org/teavm/model/analysis/test/NullnessAnalysisTest.java @@ -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"; diff --git a/core/src/test/resources/model/analysis/nullness/exception.extended.txt b/core/src/test/resources/model/analysis/nullness/exception.extended.txt new file mode 100644 index 000000000..7315d4c4e --- /dev/null +++ b/core/src/test/resources/model/analysis/nullness/exception.extended.txt @@ -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 \ No newline at end of file diff --git a/core/src/test/resources/model/analysis/nullness/exception.original.txt b/core/src/test/resources/model/analysis/nullness/exception.original.txt new file mode 100644 index 000000000..0db3a0707 --- /dev/null +++ b/core/src/test/resources/model/analysis/nullness/exception.original.txt @@ -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 \ No newline at end of file