From f320e3abd4541e4164b8ab2e20b62d738eba2616 Mon Sep 17 00:00:00 2001 From: Egor Ushakov Date: Fri, 14 Dec 2018 17:56:47 +0300 Subject: [PATCH] IDEA-204223 Decompiler doesn't add mandatory narrowing cast on integer type --- .../modules/decompiler/ExprProcessor.java | 20 +- .../decompiler/exps/InvocationExprent.java | 19 +- .../modules/decompiler/exps/NewExprent.java | 8 +- testData/classes/pkg/TestPrimitives.class | Bin 6576 -> 6931 bytes testData/results/TestPrimitives.dec | 922 +++++++++--------- testData/src/pkg/TestPrimitives.java | 6 + 6 files changed, 499 insertions(+), 476 deletions(-) diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/ExprProcessor.java b/src/org/jetbrains/java/decompiler/modules/decompiler/ExprProcessor.java index aadd0b1..2b97f00 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/ExprProcessor.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/ExprProcessor.java @@ -1,6 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.java.decompiler.modules.decompiler; import org.jetbrains.java.decompiler.code.CodeConstants; @@ -855,7 +853,7 @@ public class ExprProcessor implements CodeConstants { int indent, boolean castNull, BytecodeMappingTracer tracer) { - return getCastedExprent(exprent, leftType, buffer, indent, castNull, false, false, tracer); + return getCastedExprent(exprent, leftType, buffer, indent, castNull, false, false, false, tracer); } public static boolean getCastedExprent(Exprent exprent, @@ -865,7 +863,21 @@ public class ExprProcessor implements CodeConstants { boolean castNull, boolean castAlways, boolean castNarrowing, + boolean unbox, BytecodeMappingTracer tracer) { + + if (unbox) { + // "unbox" invocation parameters, e.g. 'byteSet.add((byte)123)' or 'new ShortContainer((short)813)' + if (exprent.type == Exprent.EXPRENT_INVOCATION && ((InvocationExprent)exprent).isBoxingCall()) { + InvocationExprent invocationExprent = (InvocationExprent)exprent; + exprent = invocationExprent.getLstParameters().get(0); + int paramType = invocationExprent.getDescriptor().params[0].type; + if (exprent.type == Exprent.EXPRENT_CONST && ((ConstExprent)exprent).getConstType().type != paramType) { + leftType = new VarType(paramType); + } + } + } + VarType rightType = exprent.getExprType(); boolean cast = diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java index 1abaf32..3fe26b3 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java @@ -1,6 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.java.decompiler.modules.decompiler.exps; import org.jetbrains.java.decompiler.code.CodeConstants; @@ -214,7 +212,7 @@ public class InvocationExprent extends Exprent { if (isBoxingCall() && canIgnoreBoxing) { // process general "boxing" calls, e.g. 'Object[] data = { true }' or 'Byte b = 123' // here 'byte' and 'short' values do not need an explicit narrowing type cast - ExprProcessor.getCastedExprent(lstParameters.get(0), descriptor.params[0], buf, indent, false, false, false, tracer); + ExprProcessor.getCastedExprent(lstParameters.get(0), descriptor.params[0], buf, indent, false, false, false, false, tracer); return buf; } @@ -351,9 +349,8 @@ public class InvocationExprent extends Exprent { TextBuffer buff = new TextBuffer(); boolean ambiguous = setAmbiguousParameters.get(i); - Exprent param = unboxIfNeeded(lstParameters.get(i)); // 'byte' and 'short' literals need an explicit narrowing type cast when used as a parameter - ExprProcessor.getCastedExprent(param, descriptor.params[i], buff, indent, true, ambiguous, true, tracer); + ExprProcessor.getCastedExprent(lstParameters.get(i), descriptor.params[i], buff, indent, true, ambiguous, true, true, tracer); // the last "new Object[0]" in the vararg call is not printed if (buff.length() > 0) { @@ -372,14 +369,6 @@ public class InvocationExprent extends Exprent { return buf; } - public static Exprent unboxIfNeeded(Exprent param) { - // "unbox" invocation parameters, e.g. 'byteSet.add((byte)123)' or 'new ShortContainer((short)813)' - if (param.type == Exprent.EXPRENT_INVOCATION && ((InvocationExprent)param).isBoxingCall()) { - param = ((InvocationExprent)param).lstParameters.get(0); - } - return param; - } - private boolean isVarArgCall() { StructClass cl = DecompilerContext.getStructContext().getClass(classname); if (cl != null) { @@ -398,7 +387,7 @@ public class InvocationExprent extends Exprent { return false; } - private boolean isBoxingCall() { + public boolean isBoxingCall() { if (isStatic && "valueOf".equals(name) && lstParameters.size() == 1) { int paramType = lstParameters.get(0).getExprType().type; diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/NewExprent.java b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/NewExprent.java index 84ac1ac..d915a5d 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/NewExprent.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/NewExprent.java @@ -1,6 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.java.decompiler.modules.decompiler.exps; import org.jetbrains.java.decompiler.code.CodeConstants; @@ -282,7 +280,7 @@ public class NewExprent extends Exprent { boolean firstParam = true; for (int i = start; i < parameters.size(); i++) { if (mask == null || mask.get(i) == null) { - Exprent expr = InvocationExprent.unboxIfNeeded(parameters.get(i)); + Exprent expr = parameters.get(i); VarType leftType = constructor.getDescriptor().params[i]; if (i == parameters.size() - 1 && expr.getExprType() == VarType.VARTYPE_NULL && probablySyntheticParameter(leftType.value)) { @@ -293,7 +291,7 @@ public class NewExprent extends Exprent { buf.append(", "); } - ExprProcessor.getCastedExprent(expr, leftType, buf, indent, true, false, true, tracer); + ExprProcessor.getCastedExprent(expr, leftType, buf, indent, true, false, true, true, tracer); firstParam = false; } diff --git a/testData/classes/pkg/TestPrimitives.class b/testData/classes/pkg/TestPrimitives.class index 1dad0d2fa50e49c17bf63e6886a417c2e77226d6..9c52484fa274649d2daf063c8fe273930b552429 100644 GIT binary patch literal 6931 zcmb7J3w%@68ULRqZPN4tX_^*FK`T-zp|liGu^{w;RaikFh--DaG=w(LHYH6_WKK4> zIdz-!wdoW$H|Jwhrq11VqR!1dopUeUbZ_S#Ztm@zb91`?cka#2O-bYjKknf>-#y>| ze6RDJ?}o=;fAA3i%hj>~I`9P0tPx=T1K; zvqLgG6u`rHM5r$Xuo;gE_2mG*g2#mVY5-ru*M<6q2e`RCfN$bkGJQONZ{rD}z7xQc z_^wdj3!oL>7wQLo{7`V8lHqATek9O8mf;yco)z?;$naA^|CtOw7vNvW@Jl~_CD_l& z@N2<-UWVWJ@LPfZoeaO1JzkLE59RnHUi9NnKKwarb0mPj;IDrCO&0uJhJVQLk_`X! z;bm|8881Ipw&vC6qpv*q>`dYQONLkc__rUg`tct>{u{swyynOM{CM4uH~b2IrF^P{ z7AOyGQeK}b4PYzRs51V`ckqvqat(fqazcU@Dy_)44a3 z2ii$f60wn$Vpp|m`HwU+t9Sw$5L z9ddilfH(Gu^5qtn<_W7)SOLw__`-_{&&n5SBAj(OK~Yy&>vMwID&chtuR?=a<_mLe zPF8#+ES(&cZtXf#7bY0_8h5m_hKT%hM`?RyRo+U8l`NZ)GsIpOcCWKMC<~|Qg|x2F z###60HWs4`ZLDLL+gLlI(8gBWWnoZnY| z4AtkGC(b7<9c7+(o;*M2c8JN~5iBD^$Cp!{M1im^XNET}ESQf57dbmC%*PNy!A$X3KtBV(ELcs!G03i#rw;n7%HXJFStD(gunSQw^7GqL!t4Y5(X=*-Tr z&~%JvQglFaWS}cHG_)nLdpwyI#L_*np>ZMvWl>jbER%cX8IFxQhhjXF9BMfuHa19H zDpr$U-S&=VE8NMJ!S3a&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/TestPrimitives.dec b/testData/results/TestPrimitives.dec index 8809dcc..bc930a5 100644 --- a/testData/results/TestPrimitives.dec +++ b/testData/results/TestPrimitives.dec @@ -1,558 +1,571 @@ package pkg; +import java.util.HashMap; + public class TestPrimitives { public void printAll() { - this.printBoolean(true);// 6 - this.printByte((byte)123);// 7 - this.printShort((short)257);// 8 - this.printInt(123);// 9 - this.printLong(123L);// 10 - this.printFloat(1.23F);// 11 - this.printDouble(1.23D);// 12 - this.printChar('Z');// 13 - this.printBooleanBoxed(true);// 15 - this.printByteBoxed((byte)123);// 16 - this.printShortBoxed((short)257);// 17 - this.printIntBoxed(1);// 18 - this.printIntBoxed(40000);// 19 - this.printLongBoxed(123L);// 20 - this.printFloatBoxed(1.23F);// 21 - this.printDoubleBoxed(1.23D);// 22 - this.printCharBoxed('Z');// 23 - this.printBoolean(Boolean.valueOf("true"));// 25 - this.printByte(Byte.valueOf("123"));// 26 - this.printShort(Short.valueOf("257"));// 27 - this.printInt(Integer.valueOf("123"));// 28 - this.printLong(Long.valueOf("123"));// 29 - this.printFloat(Float.valueOf("1.23"));// 30 - this.printDouble(Double.valueOf("1.23"));// 31 - this.printChar(new Character('Z'));// 32 - this.printInt(this.getInteger());// 34 - this.printChar(this.getCharacter());// 35 - System.out.printf("%b, %d, %d, %d, %c, %d", true, 1, 213, 40000, 'c', 42L);// 37 - System.out.printf("%b, %d, %d, %d", this.getBoolean(), this.getByte(), this.getShort(), this.getInt());// 38 - new TestPrimitives(false, (byte)123, (short)257, 40000, 123L, 3.14F, 1.618D, 'A');// 40 - new TestPrimitives('A', 1.618D, 3.14F, 123L, 40000, (short)257, (byte)123, false);// 41 - new TestPrimitives(Boolean.valueOf("false"), Byte.valueOf("123"), Short.valueOf("257"), Integer.valueOf("40000"), Long.valueOf("123"), Float.valueOf("3.14"), Double.valueOf("1.618"), new Character('A'));// 42 43 - }// 44 + this.printBoolean(true);// 8 + this.printByte((byte)123);// 9 + this.printShort((short)257);// 10 + this.printInt(123);// 11 + this.printLong(123L);// 12 + this.printFloat(1.23F);// 13 + this.printDouble(1.23D);// 14 + this.printChar('Z');// 15 + this.printBooleanBoxed(true);// 17 + this.printByteBoxed((byte)123);// 18 + this.printShortBoxed((short)257);// 19 + this.printIntBoxed(1);// 20 + this.printIntBoxed(40000);// 21 + this.printLongBoxed(123L);// 22 + this.printFloatBoxed(1.23F);// 23 + this.printDoubleBoxed(1.23D);// 24 + this.printCharBoxed('Z');// 25 + this.printBoolean(Boolean.valueOf("true"));// 27 + this.printByte(Byte.valueOf("123"));// 28 + this.printShort(Short.valueOf("257"));// 29 + this.printInt(Integer.valueOf("123"));// 30 + this.printLong(Long.valueOf("123"));// 31 + this.printFloat(Float.valueOf("1.23"));// 32 + this.printDouble(Double.valueOf("1.23"));// 33 + this.printChar(new Character('Z'));// 34 + this.printInt(this.getInteger());// 36 + this.printChar(this.getCharacter());// 37 + System.out.printf("%b, %d, %d, %d, %c, %d", true, 1, 213, 40000, 'c', 42L);// 39 + System.out.printf("%b, %d, %d, %d", this.getBoolean(), this.getByte(), this.getShort(), this.getInt());// 40 + new TestPrimitives(false, (byte)123, (short)257, 40000, 123L, 3.14F, 1.618D, 'A');// 42 + new TestPrimitives('A', 1.618D, 3.14F, 123L, 40000, (short)257, (byte)123, false);// 43 + new TestPrimitives(Boolean.valueOf("false"), Byte.valueOf("123"), Short.valueOf("257"), Integer.valueOf("40000"), Long.valueOf("123"), Float.valueOf("3.14"), Double.valueOf("1.618"), new Character('A'));// 44 45 + }// 46 private TestPrimitives(boolean bool, byte b, short s, int i, long l, float f, double d, char c) { - System.out.printf("%b, %d, %d, %d, %d, %.2f, %.2f, %c", bool, b, s, i, l, f, d, c);// 47 - }// 48 + System.out.printf("%b, %d, %d, %d, %d, %.2f, %.2f, %c", bool, b, s, i, l, f, d, c);// 49 + }// 50 private TestPrimitives(Character c, Double d, Float f, Long l, Integer i, Short s, Byte b, Boolean bool) { - System.out.printf("%b, %d, %d, %d, %d, %.2f, %.2f, %c", bool, b, s, i, l, f, d, c);// 51 - }// 52 + System.out.printf("%b, %d, %d, %d, %d, %.2f, %.2f, %c", bool, b, s, i, l, f, d, c);// 53 + }// 54 public void printBoolean(boolean b) { - System.out.printf("%b", b);// 55 - }// 56 + System.out.printf("%b", b);// 57 + }// 58 public void printByte(byte b) { - System.out.printf("%d", b);// 59 - }// 60 + System.out.printf("%d", b);// 61 + }// 62 public void printShort(short s) { - System.out.printf("%d", s);// 63 - }// 64 + System.out.printf("%d", s);// 65 + }// 66 public void printInt(int i) { - System.out.printf("%d", i);// 67 - }// 68 + System.out.printf("%d", i);// 69 + }// 70 public void printLong(long l) { - System.out.printf("%d", l);// 71 - }// 72 + System.out.printf("%d", l);// 73 + }// 74 public void printFloat(float f) { - System.out.printf("%f", f);// 75 - }// 76 + System.out.printf("%f", f);// 77 + }// 78 public void printDouble(double d) { - System.out.printf("%f", d);// 79 - }// 80 + System.out.printf("%f", d);// 81 + }// 82 public void printChar(char c) { - System.out.printf("%c", c);// 83 - }// 84 + System.out.printf("%c", c);// 85 + }// 86 public void printBooleanBoxed(Boolean b) { - System.out.printf("%b", b);// 88 - }// 89 + System.out.printf("%b", b);// 90 + }// 91 public void printByteBoxed(Byte b) { - System.out.printf("%d", b);// 92 - }// 93 + System.out.printf("%d", b);// 94 + }// 95 public void printShortBoxed(Short s) { - System.out.printf("%d", s);// 96 - }// 97 + System.out.printf("%d", s);// 98 + }// 99 public void printIntBoxed(Integer i) { - System.out.printf("%d", i);// 100 - }// 101 + System.out.printf("%d", i);// 102 + }// 103 public void printLongBoxed(Long l) { - System.out.printf("%d", l);// 104 - }// 105 + System.out.printf("%d", l);// 106 + }// 107 public void printFloatBoxed(Float f) { - System.out.printf("%f", f);// 108 - }// 109 + System.out.printf("%f", f);// 110 + }// 111 public void printDoubleBoxed(Double d) { - System.out.printf("%f", d);// 112 - }// 113 + System.out.printf("%f", d);// 114 + }// 115 public void printCharBoxed(Character c) { - System.out.printf("%c", c);// 116 - }// 117 + System.out.printf("%c", c);// 118 + }// 119 public boolean getBoolean() { - return false;// 121 + return false;// 123 } public byte getByte() { - return -128;// 125 + return -128;// 127 } public short getShort() { - return -32768;// 129 + return -32768;// 131 } public int getInt() { - return 42;// 133 + return 42;// 135 } public Integer getInteger() { - return 40000;// 137 + return 40000;// 139 } public Character getCharacter() { - return 'Z';// 141 + return 'Z';// 143 } public void printNarrowed() { - this.printByte((byte)this.getInt());// 145 - this.printShort((short)this.getInt());// 146 - }// 147 + this.printByte((byte)this.getInt());// 147 + this.printShort((short)this.getInt());// 148 + }// 149 public void constructor() { - new Byte((byte)1);// 150 - }// 151 + new Byte((byte)1);// 152 + }// 153 private boolean compare(char c) { - boolean res = c > -1;// 154 - res = c > 0;// 155 - res = c > 1;// 156 - res = c > '\b';// 157 - res = c > '\t';// 158 - res = c > '\n';// 159 - res = c > '\f';// 160 - res = c > '\r';// 161 - res = c > ' ';// 162 - res = c > 'a';// 163 - res = c > 'Z';// 164 - res = c > 127;// 165 - res = c > 255;// 166 - return res;// 167 + boolean res = c > -1;// 156 + res = c > 0;// 157 + res = c > 1;// 158 + res = c > '\b';// 159 + res = c > '\t';// 160 + res = c > '\n';// 161 + res = c > '\f';// 162 + res = c > '\r';// 163 + res = c > ' ';// 164 + res = c > 'a';// 165 + res = c > 'Z';// 166 + res = c > 127;// 167 + res = c > 255;// 168 + return res;// 169 } void testAutoBoxingCallRequired(boolean value) { - Boolean.valueOf(value).hashCode();// 171 - }// 172 + Boolean.valueOf(value).hashCode();// 173 + }// 174 + + void testCastRequired() { + HashMap map = new HashMap();// 177 + map.put("test", (byte)0);// 178 + }// 179 } class 'pkg/TestPrimitives' { method 'printAll ()V' { - 1 4 - 2 4 - 6 5 - 8 5 - c 6 - f 6 - 13 7 - 15 7 - 19 8 - 1c 8 - 20 9 - 22 9 - 26 10 - 29 10 - 2d 11 - 2f 11 - 33 12 - 37 12 - 3b 13 - 40 13 - 44 14 - 4a 14 - 4e 15 - 52 15 - 56 16 - 5b 16 - 5f 17 - 65 17 - 69 18 - 6e 18 - 72 19 - 78 19 - 7c 20 - 81 20 - 85 21 - 87 21 - 8a 21 - 8d 21 - 91 22 - 93 22 - 96 22 - 99 22 - 9d 23 - 9f 23 - a2 23 - a5 23 - a9 24 - ab 24 - ae 24 - b1 24 - b5 25 - b7 25 - ba 25 - bd 25 - c1 26 - c3 26 - c6 26 - c9 26 - cd 27 - cf 27 - d2 27 - d5 27 - dd 28 - e2 28 - e5 28 - ea 29 - ed 29 - f0 29 - f5 30 - f8 30 - fb 30 - fe 31 - 101 31 - 10a 31 - 10b 31 - 111 31 - 112 31 - 118 31 - 11b 31 - 121 31 - 123 31 - 129 31 - 12b 31 - 131 31 - 134 31 - 138 31 - 13c 32 - 13f 32 - 148 32 - 14b 32 - 152 32 - 155 32 - 15c 32 - 15f 32 - 166 32 - 169 32 - 16d 32 - 175 33 - 176 33 - 178 33 - 17b 33 - 17d 33 - 180 33 - 182 33 - 185 33 - 18f 34 - 194 34 - 19a 34 - 19f 34 - 1a5 34 - 1aa 34 - 1b0 34 - 1b5 34 - 1c1 35 - 1c3 35 - 1c6 35 - 1c9 35 - 1cb 35 - 1ce 35 - 1d1 35 - 1d3 35 - 1d6 35 - 1d9 35 - 1db 35 - 1de 35 - 1e1 35 - 1e3 35 - 1e6 35 - 1e9 35 - 1eb 35 - 1ee 35 - 1f1 35 - 1f3 35 - 1f6 35 - 1fd 35 - 202 35 - 209 36 + 1 6 + 2 6 + 6 7 + 8 7 + c 8 + f 8 + 13 9 + 15 9 + 19 10 + 1c 10 + 20 11 + 22 11 + 26 12 + 29 12 + 2d 13 + 2f 13 + 33 14 + 37 14 + 3b 15 + 40 15 + 44 16 + 4a 16 + 4e 17 + 52 17 + 56 18 + 5b 18 + 5f 19 + 65 19 + 69 20 + 6e 20 + 72 21 + 78 21 + 7c 22 + 81 22 + 85 23 + 87 23 + 8a 23 + 8d 23 + 91 24 + 93 24 + 96 24 + 99 24 + 9d 25 + 9f 25 + a2 25 + a5 25 + a9 26 + ab 26 + ae 26 + b1 26 + b5 27 + b7 27 + ba 27 + bd 27 + c1 28 + c3 28 + c6 28 + c9 28 + cd 29 + cf 29 + d2 29 + d5 29 + dd 30 + e2 30 + e5 30 + ea 31 + ed 31 + f0 31 + f5 32 + f8 32 + fb 32 + fe 33 + 101 33 + 10a 33 + 10b 33 + 111 33 + 112 33 + 118 33 + 11b 33 + 121 33 + 123 33 + 129 33 + 12b 33 + 131 33 + 134 33 + 138 33 + 13c 34 + 13f 34 + 148 34 + 14b 34 + 152 34 + 155 34 + 15c 34 + 15f 34 + 166 34 + 169 34 + 16d 34 + 175 35 + 176 35 + 178 35 + 17b 35 + 17d 35 + 180 35 + 182 35 + 185 35 + 18f 36 + 194 36 + 19a 36 + 19f 36 + 1a5 36 + 1aa 36 + 1b0 36 + 1b5 36 + 1c1 37 + 1c3 37 + 1c6 37 + 1c9 37 + 1cb 37 + 1ce 37 + 1d1 37 + 1d3 37 + 1d6 37 + 1d9 37 + 1db 37 + 1de 37 + 1e1 37 + 1e3 37 + 1e6 37 + 1e9 37 + 1eb 37 + 1ee 37 + 1f1 37 + 1f3 37 + 1f6 37 + 1fd 37 + 202 37 + 209 38 } method ' (ZBSIJFDC)V' { - 4 39 - 7 39 - 11 39 - 18 39 - 1f 39 - 27 39 - 2f 39 - 37 39 - 40 39 - 49 39 - 4d 39 - 51 40 + 4 41 + 7 41 + 11 41 + 18 41 + 1f 41 + 27 41 + 2f 41 + 37 41 + 40 41 + 49 41 + 4d 41 + 51 42 } method ' (Ljava/lang/Character;Ljava/lang/Double;Ljava/lang/Float;Ljava/lang/Long;Ljava/lang/Integer;Ljava/lang/Short;Ljava/lang/Byte;Ljava/lang/Boolean;)V' { - 4 43 - 7 43 - 35 43 - 39 44 + 4 45 + 7 45 + 35 45 + 39 46 } method 'printBoolean (Z)V' { - 0 47 - 3 47 - c 47 - 10 47 - 14 48 + 0 49 + 3 49 + c 49 + 10 49 + 14 50 } method 'printByte (B)V' { - 0 51 - 3 51 - c 51 - 10 51 - 14 52 + 0 53 + 3 53 + c 53 + 10 53 + 14 54 } method 'printShort (S)V' { - 0 55 - 3 55 - c 55 - 10 55 - 14 56 + 0 57 + 3 57 + c 57 + 10 57 + 14 58 } method 'printInt (I)V' { - 0 59 - 3 59 - c 59 - 10 59 - 14 60 + 0 61 + 3 61 + c 61 + 10 61 + 14 62 } method 'printLong (J)V' { - 0 63 - 3 63 - c 63 - 10 63 - 14 64 + 0 65 + 3 65 + c 65 + 10 65 + 14 66 } method 'printFloat (F)V' { - 0 67 - 3 67 - c 67 - 10 67 - 14 68 + 0 69 + 3 69 + c 69 + 10 69 + 14 70 } method 'printDouble (D)V' { - 0 71 - 3 71 - c 71 - 10 71 - 14 72 + 0 73 + 3 73 + c 73 + 10 73 + 14 74 } method 'printChar (C)V' { - 0 75 - 3 75 - c 75 - 10 75 - 14 76 + 0 77 + 3 77 + c 77 + 10 77 + 14 78 } method 'printBooleanBoxed (Ljava/lang/Boolean;)V' { - 0 79 - 3 79 - d 79 - 11 80 + 0 81 + 3 81 + d 81 + 11 82 } method 'printByteBoxed (Ljava/lang/Byte;)V' { - 0 83 - 3 83 - d 83 - 11 84 + 0 85 + 3 85 + d 85 + 11 86 } method 'printShortBoxed (Ljava/lang/Short;)V' { - 0 87 - 3 87 - d 87 - 11 88 + 0 89 + 3 89 + d 89 + 11 90 } method 'printIntBoxed (Ljava/lang/Integer;)V' { - 0 91 - 3 91 - d 91 - 11 92 + 0 93 + 3 93 + d 93 + 11 94 } method 'printLongBoxed (Ljava/lang/Long;)V' { - 0 95 - 3 95 - d 95 - 11 96 + 0 97 + 3 97 + d 97 + 11 98 } method 'printFloatBoxed (Ljava/lang/Float;)V' { - 0 99 - 3 99 - d 99 - 11 100 + 0 101 + 3 101 + d 101 + 11 102 } method 'printDoubleBoxed (Ljava/lang/Double;)V' { - 0 103 - 3 103 - d 103 - 11 104 + 0 105 + 3 105 + d 105 + 11 106 } method 'printCharBoxed (Ljava/lang/Character;)V' { - 0 107 - 3 107 - d 107 - 11 108 + 0 109 + 3 109 + d 109 + 11 110 } method 'getBoolean ()Z' { - 0 111 - 1 111 + 0 113 + 1 113 } method 'getByte ()B' { - 0 115 - 2 115 + 0 117 + 2 117 } method 'getShort ()S' { - 0 119 - 3 119 + 0 121 + 3 121 } method 'getInt ()I' { - 0 123 - 2 123 + 0 125 + 2 125 } method 'getInteger ()Ljava/lang/Integer;' { - 0 127 - 2 127 - 5 127 + 0 129 + 2 129 + 5 129 } method 'getCharacter ()Ljava/lang/Character;' { - 0 131 - 2 131 - 5 131 + 0 133 + 2 133 + 5 133 } method 'printNarrowed ()V' { - 2 135 - 5 135 - 6 135 - b 136 - e 136 - f 136 - 12 137 + 2 137 + 5 137 + 6 137 + b 138 + e 138 + f 138 + 12 139 } method 'constructor ()V' { - 4 140 - 9 141 + 4 142 + 9 143 } method 'compare (C)Z' { - 1 144 - 2 144 - a 144 - c 145 - 14 145 - 16 146 - 17 146 - 1f 146 - 21 147 - 23 147 - 2b 147 - 2d 148 - 2f 148 - 37 148 - 39 149 - 3b 149 - 43 149 - 45 150 - 47 150 - 4f 150 - 51 151 - 53 151 - 5b 151 - 5d 152 - 5f 152 - 67 152 - 69 153 - 6b 153 - 73 153 - 75 154 - 77 154 - 7f 154 - 81 155 - 83 155 - 8b 155 - 8d 156 - 90 156 - 98 156 - 9a 157 + 1 146 + 2 146 + a 146 + c 147 + 14 147 + 16 148 + 17 148 + 1f 148 + 21 149 + 23 149 + 2b 149 + 2d 150 + 2f 150 + 37 150 + 39 151 + 3b 151 + 43 151 + 45 152 + 47 152 + 4f 152 + 51 153 + 53 153 + 5b 153 + 5d 154 + 5f 154 + 67 154 + 69 155 + 6b 155 + 73 155 + 75 156 + 77 156 + 7f 156 + 81 157 + 83 157 + 8b 157 + 8d 158 + 90 158 + 98 158 + 9a 159 } method 'testAutoBoxingCallRequired (Z)V' { - 1 161 - 4 161 - 8 162 + 1 163 + 4 163 + 8 164 + } + + method 'testCastRequired ()V' { + 7 167 + 9 168 + b 168 + f 168 + 13 169 } } Lines mapping: -6 <-> 5 -7 <-> 6 8 <-> 7 9 <-> 8 10 <-> 9 11 <-> 10 12 <-> 11 13 <-> 12 -15 <-> 13 -16 <-> 14 +14 <-> 13 +15 <-> 14 17 <-> 15 18 <-> 16 19 <-> 17 @@ -560,72 +573,72 @@ Lines mapping: 21 <-> 19 22 <-> 20 23 <-> 21 -25 <-> 22 -26 <-> 23 +24 <-> 22 +25 <-> 23 27 <-> 24 28 <-> 25 29 <-> 26 30 <-> 27 31 <-> 28 32 <-> 29 -34 <-> 30 -35 <-> 31 -37 <-> 32 -38 <-> 33 -40 <-> 34 -41 <-> 35 +33 <-> 30 +34 <-> 31 +36 <-> 32 +37 <-> 33 +39 <-> 34 +40 <-> 35 42 <-> 36 -43 <-> 36 -44 <-> 37 -47 <-> 40 -48 <-> 41 -51 <-> 44 -52 <-> 45 -55 <-> 48 -56 <-> 49 -59 <-> 52 -60 <-> 53 -63 <-> 56 -64 <-> 57 -67 <-> 60 -68 <-> 61 -71 <-> 64 -72 <-> 65 -75 <-> 68 -76 <-> 69 -79 <-> 72 -80 <-> 73 -83 <-> 76 -84 <-> 77 -88 <-> 80 -89 <-> 81 -92 <-> 84 -93 <-> 85 -96 <-> 88 -97 <-> 89 -100 <-> 92 -101 <-> 93 -104 <-> 96 -105 <-> 97 -108 <-> 100 -109 <-> 101 -112 <-> 104 -113 <-> 105 -116 <-> 108 -117 <-> 109 -121 <-> 112 -125 <-> 116 -129 <-> 120 -133 <-> 124 -137 <-> 128 -141 <-> 132 -145 <-> 136 -146 <-> 137 +43 <-> 37 +44 <-> 38 +45 <-> 38 +46 <-> 39 +49 <-> 42 +50 <-> 43 +53 <-> 46 +54 <-> 47 +57 <-> 50 +58 <-> 51 +61 <-> 54 +62 <-> 55 +65 <-> 58 +66 <-> 59 +69 <-> 62 +70 <-> 63 +73 <-> 66 +74 <-> 67 +77 <-> 70 +78 <-> 71 +81 <-> 74 +82 <-> 75 +85 <-> 78 +86 <-> 79 +90 <-> 82 +91 <-> 83 +94 <-> 86 +95 <-> 87 +98 <-> 90 +99 <-> 91 +102 <-> 94 +103 <-> 95 +106 <-> 98 +107 <-> 99 +110 <-> 102 +111 <-> 103 +114 <-> 106 +115 <-> 107 +118 <-> 110 +119 <-> 111 +123 <-> 114 +127 <-> 118 +131 <-> 122 +135 <-> 126 +139 <-> 130 +143 <-> 134 147 <-> 138 -150 <-> 141 -151 <-> 142 -154 <-> 145 -155 <-> 146 +148 <-> 139 +149 <-> 140 +152 <-> 143 +153 <-> 144 156 <-> 147 157 <-> 148 158 <-> 149 @@ -638,8 +651,13 @@ Lines mapping: 165 <-> 156 166 <-> 157 167 <-> 158 -171 <-> 162 -172 <-> 163 +168 <-> 159 +169 <-> 160 +173 <-> 164 +174 <-> 165 +177 <-> 168 +178 <-> 169 +179 <-> 170 Not mapped: -46 -50 +48 +52 diff --git a/testData/src/pkg/TestPrimitives.java b/testData/src/pkg/TestPrimitives.java index 55bd806..3630252 100644 --- a/testData/src/pkg/TestPrimitives.java +++ b/testData/src/pkg/TestPrimitives.java @@ -1,5 +1,7 @@ package pkg; +import java.util.*; + public class TestPrimitives { public void printAll() { @@ -171,4 +173,8 @@ public class TestPrimitives { Boolean.valueOf(value).hashCode(); } + void testCastRequired() { + HashMap map = new HashMap(); + map.put("test", (byte) 0); + } }