From 44ba5816f2c1ab4905be782f0c6afdbff4398452 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Tue, 14 Apr 2015 12:31:28 +0300 Subject: [PATCH] IDEA-138578 Debugger spuriously jumps to decompiled method signature --- .../java/decompiler/main/TextBuffer.java | 24 +++-- .../modules/decompiler/exps/IfExprent.java | 2 +- testData/classes/pkg/TestClassLoop.class | Bin 880 -> 1336 bytes testData/results/TestClassLambda.dec | 4 +- testData/results/TestClassLoop.dec | 88 ++++++++++++++++++ testData/results/TestClassTypes.dec | 1 + testData/results/TestClassVar.dec | 6 +- testData/results/TestTryCatchFinally.dec | 2 +- testData/src/pkg/TestClassLoop.java | 33 +++++++ 9 files changed, 146 insertions(+), 14 deletions(-) diff --git a/src/org/jetbrains/java/decompiler/main/TextBuffer.java b/src/org/jetbrains/java/decompiler/main/TextBuffer.java index 93e5193..95afc50 100644 --- a/src/org/jetbrains/java/decompiler/main/TextBuffer.java +++ b/src/org/jetbrains/java/decompiler/main/TextBuffer.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -150,9 +150,12 @@ public class TextBuffer { while ((lineEnd = myStringBuilder.indexOf(myLineSeparator, lineStart)) > 0) { ++count; sb.append(myStringBuilder.substring(lineStart, lineEnd)); - Integer integer = myLineMapping.get(count); - if (integer != null) { - sb.append("// ").append(integer); + Set integers = myLineMapping.get(count); + if (integers != null) { + sb.append("//"); + for (Integer integer : integers) { + sb.append(' ').append(integer); + } } sb.append(myLineSeparator); lineStart = lineEnd + length; @@ -302,17 +305,18 @@ public class TextBuffer { return myStringBuilder; } - private Map myLineMapping = null; // new to original + private Map> myLineMapping = null; // new to original public void dumpOriginalLineNumbers(int[] lineMapping) { if (lineMapping.length > 0) { - myLineMapping = new HashMap(); + myLineMapping = new HashMap>(); for (int i = 0; i < lineMapping.length; i+=2) { int key = lineMapping[i + 1]; - int value = lineMapping[i]; - Integer existing = myLineMapping.get(key); - if (existing == null || value < existing) { - myLineMapping.put(key, value); + Set existing = myLineMapping.get(key); + if (existing == null) { + existing = new TreeSet(); + myLineMapping.put(key, existing); } + existing.add(lineMapping[i]); } } } diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/IfExprent.java b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/IfExprent.java index f471d45..059270f 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/IfExprent.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/IfExprent.java @@ -89,7 +89,7 @@ public class IfExprent extends Exprent { condition = stack.pop(); } else { - condition = new FunctionExprent(FUNC_TYPES[ifType], stack, null); + condition = new FunctionExprent(FUNC_TYPES[ifType], stack, bytecodeOffsets); } } diff --git a/testData/classes/pkg/TestClassLoop.class b/testData/classes/pkg/TestClassLoop.class index 1afdebfe666668b94314dd837fb2ebb9c00ecfaf..b7abc5306d1ddfb8ae4c01d0ddf0c0b4d65ef47c 100644 GIT binary patch delta 766 zcmYL`%TE(g6vn^PX=ggaU@1^QXbVcwwg?4E$48+pHeiZC3=j-H5(`dBwXc-HxMLw3 zcapBy5f`#?;|7c-niyC9HLeX(&#k0PGUwj&-QS%1oio4X&)U6TXJ5Vnm_$m03w{;- z7|?J9S2YYG;KYzft~qhtiJ*oM!XgYSxZ%Wzh8Bz}h$tA_pLj~+`|o;2+?Kg*J>1F{ z%yhZ9kuRCg37+7>i|ngxq>wG;A}dxkU&_Tp83hyj9|F5=a4U%F>>#GV&~a1bw{+ab z9RiIDAu3|z+?AKP$SNC67itnE91TmgD7}3~kPBuhXKfLrU?{`s=2o^kV-f7ZOeoE> zxWr=;j|0TT+#K6E^YKbT4WEEM@rKaBQErIsP|^7xt^K85|HVl+JWNS~Qqgse#B7Vy zQF~(>^ov6mWIaWvTv4A_(5*4pa}NHrJ!Wt~8r~IPR})-g?i4PLf4H)W%jo4**gWIA zR9@G^$55xFX(=HYcFAx^h9VhGZ{K?)!`@?PhU}5s#txzGDRhJ(PDT$A@ExG_D_Yju z^%Jyy_Zkk5{Q&ZwqrPiT?Ahq3{=?(=$klC)-j}&&AjyMDLBR~)dlx#=+|Vq0nd8ng z>}#G!dLKb7U=)jpVTphI1E!XlSmBdZR@PW~#PLaET5-sA-lz)tNIW2l0(G8BQxYmV SHLCOFO_4eFL+~~n`u+h0Y<7$Q delta 332 zcmYL?yGjFL5QV>gSN7(b)kJr_#>6CEl31we6$Aw(t&Lb%qzHtya4p0pPauSS2zv_= z3m?E|5Ffxw+Yr?GW6*&a=A8LB^XPq8+b>^F&p?As50B6#V%B4hd5;Aa9hS7nJ1jdC zY>GB3y~DGpq{t<$%jBRPpLaUf`xkN2j;~t1_i}w4-=^$SVbx~MXI<+JpDHzl+R{c{ zmL2Iv+EvHto4N@p;>vqnV<;p;=0tjHgw2e2mMF*y6Z~F8Rfit9_ZSbDci(+64gT?n zNpVb#xlD}`KaHl!q`PJ*ua5zizo!PE{3DyJCtz*_cFj`(U(H%YgW(@|BHVyLW?zyO I)5EVbKekpZ2mk;8 diff --git a/testData/results/TestClassLambda.dec b/testData/results/TestClassLambda.dec index 4b6e65f..751537c 100644 --- a/testData/results/TestClassLambda.dec +++ b/testData/results/TestClassLambda.dec @@ -84,7 +84,7 @@ public class TestClassLambda { System.out.println("hello2" + var1); };// 87 System.out.println("hello1" + var1);// 88 - };// 86 + };// 86 89 }// 90 } @@ -180,7 +180,9 @@ class 'pkg/TestClassLambda' { method 'lambda$testLambda6$4 (IILjava/lang/String;)Z' { 2 59 + 5 59 9 59 + d 59 15 59 } diff --git a/testData/results/TestClassLoop.dec b/testData/results/TestClassLoop.dec index 7e4df12..0ea725e 100644 --- a/testData/results/TestClassLoop.dec +++ b/testData/results/TestClassLoop.dec @@ -40,6 +40,39 @@ public class TestClassLoop { System.out.println("4");// 58 } } + + public static int testWhileCombined(String var0) { + int var1 = var0.length();// 63 + int var2 = 0;// 64 + boolean var3 = false;// 65 + boolean var4 = false;// 66 + int var5 = 0;// 67 + int var7 = 0;// 69 + + for(boolean var8 = false; var2 < var1; ++var2) {// 70 73 90 + char var6 = var0.charAt(var2);// 74 + if(var6 == 48) {// 75 + ++var7;// 76 + } else { + if(var6 != 46) {// 77 + break; + } + + if(var3) {// 78 + throw new NumberFormatException("multiple points");// 80 + } + + var5 = var2;// 82 + if(var4) {// 83 + var5 = var2 - 1;// 84 + } + + var3 = true;// 86 + } + } + + return var5;// 92 + } } class 'pkg/TestClassLoop' { @@ -77,6 +110,41 @@ class 'pkg/TestClassLoop' { 3a 39 3c 39 } + + method 'testWhileCombined (Ljava/lang/String;)I' { + 1 44 + 4 44 + 5 45 + 6 45 + 7 46 + 8 46 + 9 47 + a 47 + c 48 + d 48 + f 49 + 10 49 + 12 51 + 13 51 + 17 51 + 1c 52 + 1f 52 + 23 53 + 25 53 + 28 54 + 30 56 + 32 56 + 36 60 + 3d 61 + 42 61 + 44 64 + 48 65 + 4b 66 + 4e 69 + 4f 69 + 50 51 + 58 73 + } } Lines mapping: @@ -91,5 +159,25 @@ Lines mapping: 53 <-> 34 54 <-> 35 58 <-> 40 +63 <-> 45 +64 <-> 46 +65 <-> 47 +66 <-> 48 +67 <-> 49 +69 <-> 50 +70 <-> 52 +73 <-> 52 +74 <-> 53 +75 <-> 54 +76 <-> 55 +77 <-> 57 +78 <-> 61 +80 <-> 62 +82 <-> 65 +83 <-> 66 +84 <-> 67 +86 <-> 70 +90 <-> 52 +92 <-> 74 Not mapped: 39 diff --git a/testData/results/TestClassTypes.dec b/testData/results/TestClassTypes.dec index 4f10a71..c957f3f 100644 --- a/testData/results/TestClassTypes.dec +++ b/testData/results/TestClassTypes.dec @@ -79,6 +79,7 @@ class 'pkg/TestClassTypes' { 1 22 2 22 3 22 + 4 22 c 22 } diff --git a/testData/results/TestClassVar.dec b/testData/results/TestClassVar.dec index 37aa5ec..548c6f4 100644 --- a/testData/results/TestClassVar.dec +++ b/testData/results/TestClassVar.dec @@ -27,7 +27,7 @@ public class TestClassVar { while(var1 < 10) {// 47 int var2; - for(var2 = var1; var1 < 10 && var1 == 0; ++var1) {// 49 + for(var2 = var1; var1 < 10 && var1 == 0; ++var1) {// 49 51 ; } @@ -44,6 +44,7 @@ class 'pkg/TestClassVar' { 0 7 1 7 3 7 + 5 7 8 9 b 9 1f 11 @@ -65,8 +66,11 @@ class 'pkg/TestClassVar' { 0 25 1 25 3 27 + 5 27 9 29 b 29 + d 29 + 11 29 14 29 1c 33 1f 34 diff --git a/testData/results/TestTryCatchFinally.dec b/testData/results/TestTryCatchFinally.dec index 4203478..772a76e 100644 --- a/testData/results/TestTryCatchFinally.dec +++ b/testData/results/TestTryCatchFinally.dec @@ -36,7 +36,7 @@ public class TestTryCatchFinally { System.out.println("Finally");// 55 } - return -1;// 56 + return -1;// 56 57 } } diff --git a/testData/src/pkg/TestClassLoop.java b/testData/src/pkg/TestClassLoop.java index 0ecab7d..cf2d883 100644 --- a/testData/src/pkg/TestClassLoop.java +++ b/testData/src/pkg/TestClassLoop.java @@ -58,4 +58,37 @@ public class TestClassLoop { System.out.println("4"); } } + + public static int testWhileCombined(String in) { + int len = in.length(); + int i = 0; + boolean decSeen = false; + boolean signSeen = false; + int decPt = 0; + char c; + int nLeadZero = 0; + int nTrailZero= 0; + + skipLeadingZerosLoop: + while (i < len) { + c = in.charAt(i); + if (c == '0') { + nLeadZero++; + } else if (c == '.') { + if (decSeen) { + // already saw one ., this is the 2nd. + throw new NumberFormatException("multiple points"); + } + decPt = i; + if (signSeen) { + decPt -= 1; + } + decSeen = true; + } else { + break skipLeadingZerosLoop; + } + i++; + } + return decPt; + } }