From 5ac0709ec3d96a07b2b60ecd0a59b3b1239a01b0 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 1 Sep 2014 10:41:40 +0200 Subject: [PATCH] contract inference: don't go inside try because catch/finally clauses can change the outcome completely --- .../codeInspection/dataFlow/ContractInference.java | 6 ------ .../ContractInferenceFromSourceTest.groovy | 13 ------------- 2 files changed, 19 deletions(-) diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ContractInference.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ContractInference.java index 7037fac8cfea..7e178538f60f 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ContractInference.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ContractInference.java @@ -370,12 +370,6 @@ class ContractInferenceInterpreter { else if (statement instanceof PsiDoWhileStatement) { result.addAll(visitStatements(states, ((PsiDoWhileStatement)statement).getBody())); } - else if (statement instanceof PsiTryStatement) { - PsiCodeBlock block = ((PsiTryStatement)statement).getTryBlock(); - if (block != null) { - result.addAll(visitStatements(states, block.getStatements())); - } - } break; // visit only the first statement unless it's 'if' whose 'then' always returns and the next statement is effectively 'else' } diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy b/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy index c3bb014d8342..8781b7bb473a 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInspection/ContractInferenceFromSourceTest.groovy @@ -334,19 +334,6 @@ class ContractInferenceFromSourceTest extends LightCodeInsightFixtureTestCase { assert c == ['null -> null'] } - public void "test go inside try"() { - def c = inferContracts(""" - final Object foo(Object bar) { - try { - if (bar == null) return null; - bar = smth(bar); - } finally {} - return new String("abc"); - } - """) - assert c == ['null -> null'] - } - public void "test use invoked method notnull"() { def c = inferContracts(""" final Object foo(Object bar) {