EA-38867 (AIOOBE: TryWithIdenticalCatchesInspection$TryWithIdenticalCatchesVisitor.canCollapse)

This commit is contained in:
Bas Leijdekkers
2012-09-05 15:28:18 +02:00
parent 8ac8508d89
commit c0b8183243
3 changed files with 28 additions and 1 deletions
@@ -82,6 +82,10 @@ public class TryWithIdenticalCatchesInspection extends BaseInspection {
if (catchSections.length < 2) {
return;
}
final PsiParameter[] parameters = statement.getCatchBlockParameters();
if (catchSections.length != parameters.length) {
return;
}
final boolean[] duplicates = new boolean[catchSections.length];
for (int i = 0; i < catchSections.length - 1; i++) {
final PsiCatchSection catchSection = catchSections[i];
@@ -99,7 +103,6 @@ public class TryWithIdenticalCatchesInspection extends BaseInspection {
false);
final DuplicatesFinder finder = new DuplicatesFinder(new PsiElement[]{catchBlock},
inputVariables, null, Collections.<PsiVariable>emptyList());
final PsiParameter[] parameters = statement.getCatchBlockParameters();
for (int j = i + 1; j < catchSections.length; j++) {
if (duplicates[j]) {
continue;
@@ -105,4 +105,16 @@ class TryIdenticalCatches {
} catch (E1 e) {
}
}
void q() {
try {
Class.forName("bla").newInstance();
} catch (ClassNotFoundException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} catch (InstantiationException ) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} catch (IllegalAccessException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
}
@@ -108,4 +108,16 @@ class TryIdenticalCatches {
} <warning descr="catch branch identical to 'E2' branch">catch (E1 e)</warning> {
}
}
void q() {
try {
Class.forName("bla").newInstance();
} catch (ClassNotFoundException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} catch (<error descr="Cannot resolve symbol 'InstantiationException'">InstantiationException</error><error descr="Identifier expected"> </error>) {
<error descr="Cannot resolve symbol 'e'">e</error>.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} catch (IllegalAccessException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
}