Commit b5344f45 authored by Ahmed Ashour's avatar Ahmed Ashour Committed by skylot

fix: redundant byte and short cast (#538) (PR #539)

parent 0fa3842a
......@@ -97,7 +97,7 @@ public class TypeGen {
if (s == Short.MIN_VALUE) {
return "Short.MIN_VALUE";
}
return "(short) " + s;
return Short.toString(s);
}
public static String formatByte(byte b) {
......@@ -107,7 +107,7 @@ public class TypeGen {
if (b == Byte.MIN_VALUE) {
return "Byte.MIN_VALUE";
}
return "(byte) " + b;
return Byte.toString(b);
}
public static String formatInteger(int i) {
......
package jadx.tests.integration.arrays;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
import jadx.core.dex.nodes.ClassNode;
import jadx.tests.api.IntegrationTest;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
public class TestRedundantType extends IntegrationTest {
public static class TestCls {
public byte[] method() {
return new byte[]{10, 11, 12};
}
}
@Test
public void test() {
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();
assertThat(code, containsString("return new byte[]{10, 11, 12};"));
}
public static class TestByte {
public byte[] method() {
byte[] arr = new byte[50];
arr[10] = 126;
arr[20] = 127;
arr[30] = (byte) 128;
arr[40] = (byte) 129;
return arr;
}
}
@Test
public void testByte() {
ClassNode cls = getClassNode(TestByte.class);
String code = cls.getCode().toString();
assertThat(code, containsString("arr[10] = 126"));
assertThat(code, containsString("arr[20] = Byte.MAX_VALUE"));
assertThat(code, containsString("arr[30] = Byte.MIN_VALUE"));
assertThat(code, containsString("arr[40] = -127"));
assertEquals(-127, new TestByte().method()[40]);
}
public static class TestShort {
public short[] method() {
short[] arr = new short[50];
arr[10] = 32766;
arr[20] = 32767;
arr[30] = (short) 32768;
arr[40] = (short) 32769;
return arr;
}
}
@Test
public void testShort() {
ClassNode cls = getClassNode(TestShort.class);
String code = cls.getCode().toString();
assertThat(code, containsString("arr[10] = 32766"));
assertThat(code, containsString("arr[20] = Short.MAX_VALUE"));
assertThat(code, containsString("arr[30] = Short.MIN_VALUE"));
assertThat(code, containsString("arr[40] = -32767"));
assertEquals(-32767, new TestShort().method()[40]);
}
}
......@@ -41,7 +41,7 @@ public class TestTypeResolver4 extends IntegrationTest {
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();
assertThat(code, containsOne("(strArray[end] != (byte) 0 || strArray[end + 1] != (byte) 0)"));
assertThat(code, containsOne("(strArray[end] != 0 || strArray[end + 1] != 0)"));
}
@Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment