Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emit right variable name for catch variables, fixes #445 #446

Draft
wants to merge 1 commit into
base: develop/1.11.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,25 @@ protected CatchStatement(Statement head, Statement next, Set<Statement> setHandl
if (setHandlers.contains(stat)) {
stats.addWithKey(stat, stat.id);
exctstrings.add(new ArrayList<>(edge.getExceptions()));

vars.add(new VarExprent(DecompilerContext.getCounterContainer().getCounterAndIncrement(CounterContainer.VAR_COUNTER),
new VarType(CodeType.OBJECT, 0, edge.getExceptions().get(0)),
// FIXME: for now simply the first type. Should get the first common superclass when possible.
DecompilerContext.getVarProcessor()));

// FIXME: for now simply the first type. Should get the first common superclass when possible.
VarType varType = new VarType(CodeType.OBJECT, 0, edge.getExceptions().get(0));
int varIndex;
if (stat instanceof BasicBlockStatement) {
BasicBlockStatement bbs = (BasicBlockStatement) stat;
varIndex = bbs.getBlock().getSeq().getInstr(0).operand(0);
} else if (stat instanceof SequenceStatement) {
SequenceStatement seq = (SequenceStatement) stat;
if (seq.getFirst() instanceof BasicBlockStatement) {
BasicBlockStatement bbs = (BasicBlockStatement) seq.getFirst();
varIndex = bbs.getBlock().getSeq().getInstr(0).operand(0);
} else {
varIndex = DecompilerContext.getCounterContainer().getCounterAndIncrement(CounterContainer.VAR_COUNTER);
}
} else {
varIndex = DecompilerContext.getCounterContainer().getCounterAndIncrement(CounterContainer.VAR_COUNTER);
}
vars.add(new VarExprent(varIndex, varType, DecompilerContext.getVarProcessor()));
}
}

Expand Down
16 changes: 16 additions & 0 deletions test/org/jetbrains/java/decompiler/SingleClassesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
public class SingleClassesTest extends SingleClassesTestBase {
@Override
protected void registerAll() {
// registerSet("Default", this::dum,
// IFernflowerPreferences.BYTECODE_SOURCE_MAPPING, "1",
// IFernflowerPreferences.DUMP_ORIGINAL_LINES, "1",
// IFernflowerPreferences.DUMP_EXCEPTION_ON_ERROR, "0",
// IFernflowerPreferences.IGNORE_INVALID_BYTECODE, "1",
// IFernflowerPreferences.VERIFY_ANONYMOUS_CLASSES, "1",
// IFernflowerPreferences.INCLUDE_ENTIRE_CLASSPATH, "0",
// IFernflowerPreferences.TERNARY_CONDITIONS, "1",
// IFernflowerPreferences.FORCE_JSR_INLINE, "1",
// IFernflowerPreferences.USE_DEBUG_VAR_NAMES, "1"
// );
// if (true) return;
registerSet("Default", this::registerDefault,
IFernflowerPreferences.BYTECODE_SOURCE_MAPPING, "1",
IFernflowerPreferences.DUMP_ORIGINAL_LINES, "1",
Expand Down Expand Up @@ -154,6 +166,10 @@ public String getMethodDoc(StructClass structClass, StructMethod structMethod) {
// TODO: user renamer class test
}

private void dum() {
register(JAVA_8, "TestTryCatchFinally");
}

private void registerDefault() {
register(JAVA_8, "TestEnhancedForLoops");
register(JAVA_8, "TestPrimitiveNarrowing");
Expand Down
4 changes: 2 additions & 2 deletions testData/bulk/pkg/res/Loader.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public String getResource() {
stream.read(bytes);
stream.close();
return new String(bytes, "UTF-8");
} catch (Exception var5) {
throw new RuntimeException("Resource load failed", var5);
} catch (Exception e) {
throw new RuntimeException("Resource load failed", e);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions testData/results/pkg/TestClassLoop.dec
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class TestClassLoop {
if (!a) {// 49
return;// 50
}
} catch (Exception var2) {// 53
} catch (Exception e) {// 53
System.out.println("1");// 54
}
}
Expand Down Expand Up @@ -96,7 +96,7 @@ public class TestClassLoop {
}

i = j++ / i;// 115
} catch (RuntimeException var4) {// 117
} catch (RuntimeException re) {// 117
i = 10;// 118
}
}
Expand Down
4 changes: 2 additions & 2 deletions testData/results/pkg/TestClassSimpleBytecodeMapping.dec
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class TestClassSimpleBytecodeMapping {
public void test2(String a) {
try {
Integer.parseInt(a);// 34
} catch (Exception var6) {// 35
System.out.println(var6);// 36
} catch (Exception e) {// 35
System.out.println(e);// 36
} finally {
System.out.println("Finally");// 38
}
Expand Down
10 changes: 5 additions & 5 deletions testData/results/pkg/TestFinallyBlockVariableUse.dec
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ public class TestFinallyBlockVariableUse {
public int test(String s, int i, int j) {
System.out.println("a");// 5

int e;
int var10;
try {
System.out.println("b");// 7

try {
i = Integer.parseInt(s) - j;// 9
e = i;
} catch (NumberFormatException var10) {// 13
var10 = i;
} catch (NumberFormatException e) {// 13
i = j;// 14
throw var10;// 15
throw e;// 15
}
} finally {
int id = i - j;// 18
Expand All @@ -22,7 +22,7 @@ public class TestFinallyBlockVariableUse {
}
}

return e;// 11
return var10;// 11
}

private boolean condition(int i) {
Expand Down
12 changes: 6 additions & 6 deletions testData/results/pkg/TestFinallyThrow.dec
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public class TestFinallyThrow {
if (b) {// 10
return;// 11
}
} catch (Exception var22) {// 13
throw var22;// 14
} catch (Exception e) {// 13
throw e;// 14
} finally {
System.out.println(2);// 16
}
Expand All @@ -23,8 +23,8 @@ public class TestFinallyThrow {
try {
System.out.println(1);// 24
throw t;
} catch (Throwable var6) {// 25
var6.printStackTrace();// 26
} catch (Throwable e) {// 25
e.printStackTrace();// 26
} finally {
;
}
Expand All @@ -36,8 +36,8 @@ public class TestFinallyThrow {
try {
System.out.println(1);// 35
throw t;// 36
} catch (Throwable var6) {// 37
var6.printStackTrace();// 38
} catch (Throwable e) {// 37
e.printStackTrace();// 38
} finally {
;
}
Expand Down
4 changes: 2 additions & 2 deletions testData/results/pkg/TestForeachMultipleLoops.dec
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public class TestForeachMultipleLoops {

try {
System.out.println(1);// 35
} catch (Exception var9) {// 36
var9.printStackTrace();// 37
} catch (Exception e) {// 36
e.printStackTrace();// 37
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions testData/results/pkg/TestGroovyTryCatch.dec
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class TestGroovyTryCatch implements GroovyObject {
try {
try {
var1[0].call(var1[1].callGetProperty(System.class), "Hello");// 5 6
} catch (Exception var6) {// 7
} catch (Exception e) {// 7
var1[2].call(var1[3].callGetProperty(System.class), "Exception");// 8
}
} finally {
Expand All @@ -36,9 +36,9 @@ public class TestGroovyTryCatch implements GroovyObject {
try {
try {
var1[4].call(var1[5].callGetProperty(System.class), "Hello");// 13 14
} catch (Exception var8) {// 15
} catch (Exception e) {// 15
var1[6].call(var1[7].callGetProperty(System.class), "Exception");// 16
} catch (Throwable var9) {// 17
} catch (Throwable t) {// 17
var1[8].call(var1[9].callGetProperty(System.class), "Throwable");// 18
}
} finally {
Expand Down
2 changes: 1 addition & 1 deletion testData/results/pkg/TestNestedLoops2.dec
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class TestNestedLoops2 {
}

return j;// 17
} catch (RuntimeException var4) {// 11
} catch (RuntimeException re) {// 11
i = 10;// 12
}
}
Expand Down
4 changes: 2 additions & 2 deletions testData/results/pkg/TestSynchronizedLoop.dec
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public class TestSynchronizedLoop {
this.notifyAll();// 14
}// 15
}
} catch (Exception var7) {// 17
throw new RuntimeException(var7);// 18
} catch (Exception e) {// 17
throw new RuntimeException(e);// 18
}
}

Expand Down
10 changes: 5 additions & 5 deletions testData/results/pkg/TestSynchronizedTry.dec
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public class TestSynchronizedTry {

System.out.println(3);// 29
}
} catch (Exception var5) {// 30
var5.printStackTrace();// 31
} catch (Exception e) {// 30
e.printStackTrace();// 31
}

if (i > 2) {// 34
Expand All @@ -52,8 +52,8 @@ public class TestSynchronizedTry {

System.out.println(3);// 52
}
} catch (Exception var5) {// 54
var5.printStackTrace();// 55
} catch (Exception e) {// 54
e.printStackTrace();// 55
}

if (i > 2) {// 58
Expand All @@ -72,7 +72,7 @@ public class TestSynchronizedTry {
if (var1 == null) {// 72
return;// 73
}
} catch (Exception var7) {// 77
} catch (Exception var5) {// 77
break label36;
}

Expand Down
8 changes: 4 additions & 4 deletions testData/results/pkg/TestSynchronizedTryReturn.dec
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ public class TestSynchronizedTryReturn {
int var10000;
try {
var10000 = Integer.parseInt(s);// 7
} catch (Exception var5) {// 8
throw new RuntimeException(var5);// 9
} catch (Exception e) {// 8
throw new RuntimeException(e);// 9
}

return var10000;
Expand All @@ -17,8 +17,8 @@ public class TestSynchronizedTryReturn {
public int test1(String s) {
try {
return Integer.parseInt(s);// 16
} catch (Exception var3) {// 17
throw new RuntimeException(var3);// 18
} catch (Exception e) {// 17
throw new RuntimeException(e);// 18
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions testData/results/pkg/TestSynchronizedTrySharing.dec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class TestSynchronizedTrySharing {
try {
is = new FileInputStream(name);// 13
name = name.substring(50);// 14
} catch (Exception var4) {// 15
} catch (Exception e) {// 15
is.close();// 16
}
}// 18
Expand All @@ -32,7 +32,7 @@ public class TestSynchronizedTrySharing {
System.out.println(name);// 29
name = name.substring(50);// 30
}// 31
} catch (Exception var6) {// 32
} catch (Exception e) {// 32
is.close();// 33
}
}// 35
Expand Down
8 changes: 4 additions & 4 deletions testData/results/pkg/TestTryCatchFinally.dec
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ public class TestTryCatchFinally {
public void test1(String x) {
try {
System.out.println("sout1");// 24
} catch (Exception var9) {
} catch (Exception e) {
try {
System.out.println("sout2");// 27
} catch (Exception var8) {// 28
} catch (Exception var3) {// 28
}
} finally {
System.out.println("finally");// 34
Expand All @@ -27,8 +27,8 @@ public class TestTryCatchFinally {
public int test(String a) {
try {
return Integer.parseInt(a);// 51
} catch (Exception var6) {// 52
System.out.println("Error" + var6);// 53
} catch (Exception e) {// 52
System.out.println("Error" + e);// 53
} finally {
System.out.println("Finally");// 55
}
Expand Down
8 changes: 4 additions & 4 deletions testData/results/pkg/TestTryLoop.dec
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class TestTryLoop {
while (this.field) {// 16
new Scanner(file);// 17
}
} catch (FileNotFoundException var3) {// 19
var3.printStackTrace();// 20
} catch (FileNotFoundException e) {// 19
e.printStackTrace();// 20
}
}// 22

Expand All @@ -31,9 +31,9 @@ public class TestTryLoop {
}

return false;// 32
} catch (ServiceConfigurationError var5) {// 33
} catch (ServiceConfigurationError e) {// 33
System.out.println(1);// 34
} catch (NoClassDefFoundError var6) {// 35
} catch (NoClassDefFoundError e) {// 35
System.out.println(2);// 36
}
}
Expand Down
4 changes: 2 additions & 2 deletions testData/results/pkg/TestTryLoop2.dec
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public class TestTryLoop2 {
}

new Scanner(file);// 14
} catch (FileNotFoundException var3) {// 20
var3.printStackTrace();// 21
} catch (FileNotFoundException e) {// 20
e.printStackTrace();// 21
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions testData/results/pkg/TestTryLoopReturnFinally.dec
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public class TestTryLoopReturnFinally {

new Scanner(file);// 17
}
} catch (FileNotFoundException var6) {
var6.printStackTrace();// 20
} catch (FileNotFoundException e) {
e.printStackTrace();// 20
} finally {
System.out.println("Finally");// 22
}
Expand Down
4 changes: 2 additions & 2 deletions testData/results/pkg/TestTryLoopSimpleFinally.dec
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public class TestTryLoopSimpleFinally {
while (this.field) {// 15
new Scanner(file);// 16
}
} catch (FileNotFoundException var6) {// 18
var6.printStackTrace();// 19
} catch (FileNotFoundException e) {// 18
e.printStackTrace();// 19
} finally {
System.out.println("Finally");// 21
}
Expand Down
4 changes: 2 additions & 2 deletions testData/results/pkg/TestTrySynchronized.dec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class TestTrySynchronized {

try {
stream = new FileInputStream("nul");// 17
} catch (Throwable var2) {// 18
} catch (Throwable e) {// 18
stream.close();// 19
}
}// 21
Expand All @@ -32,7 +32,7 @@ public class TestTrySynchronized {
synchronized (monitor) {// 33
System.out.println("Inside second synchronized block.");// 34
}// 35
} catch (Throwable var4) {// 37
} catch (Throwable e) {// 37
stream.close();// 38
}
}// 41
Expand Down
Loading
Loading