diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/TryWithResourcesProcessor.java b/src/org/jetbrains/java/decompiler/modules/decompiler/TryWithResourcesProcessor.java index 19c3bcb2e9..84cbd2fa9c 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/TryWithResourcesProcessor.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/TryWithResourcesProcessor.java @@ -109,6 +109,10 @@ public static boolean makeTryWithResourceJ11(CatchStatement tryStatement) { return false; } + if (!tryStatement.getVars().get(0).getVarType().value.equals("java/lang/Throwable")) { + return false; + } + Statement inner = tryStatement.getStats().get(1); // Get catch block VarExprent closeable = null; @@ -125,6 +129,11 @@ public static boolean makeTryWithResourceJ11(CatchStatement tryStatement) { return false; } + CatchStatement innerTry = (CatchStatement)inner; + if (!innerTry.getVars().get(0).getVarType().value.equals("java/lang/Throwable")) { + return false; + } + Statement inTry = inner.getStats().get(0); // Catch block contains a basic block inside which has the closeable invocation @@ -164,6 +173,15 @@ public static boolean makeTryWithResourceJ11(CatchStatement tryStatement) { // Process try catch inside of if statement if (inner instanceof CatchStatement && !inner.getStats().isEmpty()) { + if (inner.getStats().isEmpty()) { + return false; + } + + CatchStatement innerTry = (CatchStatement)inner; + if (!innerTry.getVars().get(0).getVarType().value.equals("java/lang/Throwable")) { + return false; + } + Statement inTry = inner.getStats().get(0); if (inTry instanceof BasicBlockStatement && !inTry.getExprents().isEmpty()) { @@ -192,6 +210,9 @@ public static boolean makeTryWithResourceJ11(CatchStatement tryStatement) { } Set destinations = findExitpoints(tryStatement); + if (destinations.isEmpty()) { + return false; + } Statement check = tryStatement; List preds = new ArrayList<>(); diff --git a/testData/results/pkg/TestTryWithResourcesFakeTrigger.dec b/testData/results/pkg/TestTryWithResourcesFakeTrigger.dec index b2f9dcf516..8f73334e01 100644 --- a/testData/results/pkg/TestTryWithResourcesFakeTrigger.dec +++ b/testData/results/pkg/TestTryWithResourcesFakeTrigger.dec @@ -96,4 +96,4 @@ Not mapped: 16 18 30 -33 +33 \ No newline at end of file