Commit 7cdb0318 authored by Skylot's avatar Skylot

style: resolve some sonar warnings

parent 17d8516d
...@@ -247,29 +247,27 @@ public class JadxArgs { ...@@ -247,29 +247,27 @@ public class JadxArgs {
@Override @Override
public String toString() { public String toString() {
final StringBuilder sb = new StringBuilder("JadxArgs{"); return "JadxArgs{" + "inputFiles=" + inputFiles +
sb.append("inputFiles=").append(inputFiles); ", outDir=" + outDir +
sb.append(", outDir=").append(outDir); ", outDirSrc=" + outDirSrc +
sb.append(", outDirSrc=").append(outDirSrc); ", outDirRes=" + outDirRes +
sb.append(", outDirRes=").append(outDirRes); ", threadsCount=" + threadsCount +
sb.append(", threadsCount=").append(threadsCount); ", cfgOutput=" + cfgOutput +
sb.append(", cfgOutput=").append(cfgOutput); ", rawCFGOutput=" + rawCFGOutput +
sb.append(", rawCFGOutput=").append(rawCFGOutput); ", fallbackMode=" + fallbackMode +
sb.append(", fallbackMode=").append(fallbackMode); ", showInconsistentCode=" + showInconsistentCode +
sb.append(", showInconsistentCode=").append(showInconsistentCode); ", useImports=" + useImports +
sb.append(", useImports=").append(useImports); ", isSkipResources=" + isSkipResources +
sb.append(", isSkipResources=").append(isSkipResources); ", isSkipSources=" + isSkipSources +
sb.append(", isSkipSources=").append(isSkipSources); ", isDeobfuscationOn=" + isDeobfuscationOn +
sb.append(", isDeobfuscationOn=").append(isDeobfuscationOn); ", isDeobfuscationForceSave=" + isDeobfuscationForceSave +
sb.append(", isDeobfuscationForceSave=").append(isDeobfuscationForceSave); ", useSourceNameAsClassAlias=" + useSourceNameAsClassAlias +
sb.append(", useSourceNameAsClassAlias=").append(useSourceNameAsClassAlias); ", deobfuscationMinLength=" + deobfuscationMinLength +
sb.append(", deobfuscationMinLength=").append(deobfuscationMinLength); ", deobfuscationMaxLength=" + deobfuscationMaxLength +
sb.append(", deobfuscationMaxLength=").append(deobfuscationMaxLength); ", escapeUnicode=" + escapeUnicode +
sb.append(", escapeUnicode=").append(escapeUnicode); ", replaceConsts=" + replaceConsts +
sb.append(", replaceConsts=").append(replaceConsts); ", respectBytecodeAccModifiers=" + respectBytecodeAccModifiers +
sb.append(", respectBytecodeAccModifiers=").append(respectBytecodeAccModifiers); ", exportAsGradleProject=" + exportAsGradleProject +
sb.append(", exportAsGradleProject=").append(exportAsGradleProject); '}';
sb.append('}');
return sb.toString();
} }
} }
...@@ -97,7 +97,7 @@ public class TypeGen { ...@@ -97,7 +97,7 @@ public class TypeGen {
if (s == Short.MIN_VALUE) { if (s == Short.MIN_VALUE) {
return "Short.MIN_VALUE"; return "Short.MIN_VALUE";
} }
return "(short) " + Short.toString(s); return "(short) " + s;
} }
public static String formatByte(byte b) { public static String formatByte(byte b) {
...@@ -107,7 +107,7 @@ public class TypeGen { ...@@ -107,7 +107,7 @@ public class TypeGen {
if (b == Byte.MIN_VALUE) { if (b == Byte.MIN_VALUE) {
return "Byte.MIN_VALUE"; return "Byte.MIN_VALUE";
} }
return "(byte) " + Byte.toString(b); return "(byte) " + b;
} }
public static String formatInteger(int i) { public static String formatInteger(int i) {
......
...@@ -4,5 +4,5 @@ import jadx.core.dex.info.MethodInfo; ...@@ -4,5 +4,5 @@ import jadx.core.dex.info.MethodInfo;
public interface CallMthInterface { public interface CallMthInterface {
public MethodInfo getCallMth(); MethodInfo getCallMth();
} }
package jadx.core.dex.instructions.args; package jadx.core.dex.instructions.args;
import java.util.Objects;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import jadx.core.dex.info.FieldInfo; import jadx.core.dex.info.FieldInfo;
...@@ -68,7 +70,7 @@ public final class FieldArg extends RegisterArg { ...@@ -68,7 +70,7 @@ public final class FieldArg extends RegisterArg {
if (!field.equals(fieldArg.field)) { if (!field.equals(fieldArg.field)) {
return false; return false;
} }
return instArg != null ? instArg.equals(fieldArg.instArg) : fieldArg.instArg == null; return Objects.equals(instArg, fieldArg.instArg);
} }
@Override @Override
......
...@@ -151,9 +151,8 @@ public class MethodNode extends LineAttrNode implements ILoadable, ICodeNode { ...@@ -151,9 +151,8 @@ public class MethodNode extends LineAttrNode implements ILoadable, ICodeNode {
list.add(resultArg); list.add(resultArg);
} }
insnNode.getRegisterArgs(list); insnNode.getRegisterArgs(list);
int argsCount = list.size(); for (RegisterArg arg : list) {
for (int i = 0; i < argsCount; i++) { if (arg.getRegNum() >= regsCount) {
if (list.get(i).getRegNum() >= regsCount) {
throw new JadxRuntimeException("Incorrect register number in instruction: " + insnNode throw new JadxRuntimeException("Incorrect register number in instruction: " + insnNode
+ ", expected to be less than " + regsCount); + ", expected to be less than " + regsCount);
} }
......
...@@ -150,7 +150,6 @@ public class PrepareForCodeGen extends AbstractVisitor { ...@@ -150,7 +150,6 @@ public class PrepareForCodeGen extends AbstractVisitor {
} }
if (replace) { if (replace) {
insn.add(AFlag.ARITH_ONEARG); insn.add(AFlag.ARITH_ONEARG);
// insn.getResult().mergeName(arg);
} }
} }
} }
......
...@@ -24,7 +24,6 @@ import jadx.core.dex.instructions.args.FieldArg; ...@@ -24,7 +24,6 @@ import jadx.core.dex.instructions.args.FieldArg;
import jadx.core.dex.instructions.args.InsnArg; import jadx.core.dex.instructions.args.InsnArg;
import jadx.core.dex.instructions.args.InsnWrapArg; import jadx.core.dex.instructions.args.InsnWrapArg;
import jadx.core.dex.instructions.args.LiteralArg; import jadx.core.dex.instructions.args.LiteralArg;
import jadx.core.dex.instructions.args.RegisterArg;
import jadx.core.dex.instructions.mods.ConstructorInsn; import jadx.core.dex.instructions.mods.ConstructorInsn;
import jadx.core.dex.instructions.mods.TernaryInsn; import jadx.core.dex.instructions.mods.TernaryInsn;
import jadx.core.dex.nodes.BlockNode; import jadx.core.dex.nodes.BlockNode;
......
...@@ -29,7 +29,7 @@ import jadx.core.utils.exceptions.JadxRuntimeException; ...@@ -29,7 +29,7 @@ import jadx.core.utils.exceptions.JadxRuntimeException;
public class BlockSplitter extends AbstractVisitor { public class BlockSplitter extends AbstractVisitor {
// leave these instructions alone in block node // leave these instructions alone in block node
public static final Set<InsnType> SEPARATE_INSNS = EnumSet.of( private static final Set<InsnType> SEPARATE_INSNS = EnumSet.of(
InsnType.RETURN, InsnType.RETURN,
InsnType.IF, InsnType.IF,
InsnType.SWITCH, InsnType.SWITCH,
...@@ -38,6 +38,10 @@ public class BlockSplitter extends AbstractVisitor { ...@@ -38,6 +38,10 @@ public class BlockSplitter extends AbstractVisitor {
InsnType.THROW InsnType.THROW
); );
public static boolean makeSeparate(InsnType insnType) {
return SEPARATE_INSNS.contains(insnType);
}
@Override @Override
public void visit(MethodNode mth) { public void visit(MethodNode mth) {
if (mth.isNoCode()) { if (mth.isNoCode()) {
...@@ -85,7 +89,7 @@ public class BlockSplitter extends AbstractVisitor { ...@@ -85,7 +89,7 @@ public class BlockSplitter extends AbstractVisitor {
InsnType type = prevInsn.getType(); InsnType type = prevInsn.getType();
if (type == InsnType.GOTO if (type == InsnType.GOTO
|| type == InsnType.THROW || type == InsnType.THROW
|| SEPARATE_INSNS.contains(type)) { || makeSeparate(type)) {
if (type == InsnType.RETURN || type == InsnType.THROW) { if (type == InsnType.RETURN || type == InsnType.THROW) {
mth.addExitBlock(curBlock); mth.addExitBlock(curBlock);
...@@ -98,7 +102,7 @@ public class BlockSplitter extends AbstractVisitor { ...@@ -98,7 +102,7 @@ public class BlockSplitter extends AbstractVisitor {
startNew = true; startNew = true;
} else { } else {
startNew = isSplitByJump(prevInsn, insn) startNew = isSplitByJump(prevInsn, insn)
|| SEPARATE_INSNS.contains(insn.getType()) || makeSeparate(insn.getType())
|| isDoWhile(blocksMap, curBlock, insn) || isDoWhile(blocksMap, curBlock, insn)
|| insn.contains(AType.EXC_HANDLER) || insn.contains(AType.EXC_HANDLER)
|| prevInsn.contains(AFlag.TRY_LEAVE) || prevInsn.contains(AFlag.TRY_LEAVE)
......
...@@ -167,7 +167,7 @@ public class TernaryMod { ...@@ -167,7 +167,7 @@ public class TernaryMod {
} }
PhiInsn tPhi = t.getResult().getSVar().getUsedInPhi(); PhiInsn tPhi = t.getResult().getSVar().getUsedInPhi();
PhiInsn ePhi = e.getResult().getSVar().getUsedInPhi(); PhiInsn ePhi = e.getResult().getSVar().getUsedInPhi();
if (tPhi == null || ePhi == null || tPhi != ePhi) { if (ePhi == null || tPhi != ePhi) {
return false; return false;
} }
Map<Integer, Integer> map = new HashMap<>(tPhi.getArgsCount()); Map<Integer, Integer> map = new HashMap<>(tPhi.getArgsCount());
......
...@@ -321,7 +321,7 @@ public final class TypeInferenceVisitor extends AbstractVisitor { ...@@ -321,7 +321,7 @@ public final class TypeInferenceVisitor extends AbstractVisitor {
if (reg.getSVar() == var) { if (reg.getSVar() == var) {
BlockNode blockNode = entry.getValue(); BlockNode blockNode = entry.getValue();
InsnNode lastInsn = BlockUtils.getLastInsn(blockNode); InsnNode lastInsn = BlockUtils.getLastInsn(blockNode);
if (lastInsn != null && BlockSplitter.SEPARATE_INSNS.contains(lastInsn.getType())) { if (lastInsn != null && BlockSplitter.makeSeparate(lastInsn.getType())) {
if (Consts.DEBUG) { if (Consts.DEBUG) {
LOG.warn("Can't insert move for PHI in block with separate insn: {}", lastInsn); LOG.warn("Can't insert move for PHI in block with separate insn: {}", lastInsn);
} }
......
...@@ -154,7 +154,6 @@ public class Utils { ...@@ -154,7 +154,6 @@ public class Utils {
} }
} }
@SuppressWarnings("unchecked")
public static <T> List<T> lockList(List<T> list) { public static <T> List<T> lockList(List<T> list) {
if (list.isEmpty()) { if (list.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
......
...@@ -18,11 +18,8 @@ import jadx.core.xmlgen.entry.ResourceEntry; ...@@ -18,11 +18,8 @@ import jadx.core.xmlgen.entry.ResourceEntry;
import jadx.core.xmlgen.entry.ValuesParser; import jadx.core.xmlgen.entry.ValuesParser;
public class ResTableParser extends CommonBinaryParser { public class ResTableParser extends CommonBinaryParser {
private static final Logger LOG = LoggerFactory.getLogger(ResTableParser.class); private static final Logger LOG = LoggerFactory.getLogger(ResTableParser.class);
private static final int KNOWN_CONFIG_BYTES = 56;
private static final class PackageChunk { private static final class PackageChunk {
private final int id; private final int id;
private final String name; private final String name;
...@@ -150,9 +147,7 @@ public class ResTableParser extends CommonBinaryParser { ...@@ -150,9 +147,7 @@ public class ResTableParser extends CommonBinaryParser {
} }
PackageChunk pkg = new PackageChunk(id, name, typeStrings, keyStrings); PackageChunk pkg = new PackageChunk(id, name, typeStrings, keyStrings);
//if (id == 0x7F) {
resStorage.setAppPackage(name); resStorage.setAppPackage(name);
//}
while (is.getPos() < endPos) { while (is.getPos() < endPos) {
long chunkStart = is.getPos(); long chunkStart = is.getPos();
...@@ -198,7 +193,7 @@ public class ResTableParser extends CommonBinaryParser { ...@@ -198,7 +193,7 @@ public class ResTableParser extends CommonBinaryParser {
if (config.isInvalid) { if (config.isInvalid) {
String typeName = pkg.getTypeStrings()[id - 1]; String typeName = pkg.getTypeStrings()[id - 1];
LOG.warn("Invalid config flags detected: " + typeName + config.getQualifiers()); LOG.warn("Invalid config flags detected: {}{}", typeName, config.getQualifiers());
} }
int[] entryIndexes = new int[entryCount]; int[] entryIndexes = new int[entryCount];
...@@ -260,8 +255,6 @@ public class ResTableParser extends CommonBinaryParser { ...@@ -260,8 +255,6 @@ public class ResTableParser extends CommonBinaryParser {
throw new IOException("Config size < 28"); throw new IOException("Config size < 28");
} }
boolean isInvalid = false;
short mcc = (short) is.readInt16(); short mcc = (short) is.readInt16();
short mnc = (short) is.readInt16(); short mnc = (short) is.readInt16();
...@@ -321,7 +314,7 @@ public class ResTableParser extends CommonBinaryParser { ...@@ -321,7 +314,7 @@ public class ResTableParser extends CommonBinaryParser {
inputFlags, screenWidth, screenHeight, sdkVersion, inputFlags, screenWidth, screenHeight, sdkVersion,
screenLayout, uiMode, smallestScreenWidthDp, screenWidthDp, screenLayout, uiMode, smallestScreenWidthDp, screenWidthDp,
screenHeightDp, localeScript, localeVariant, screenLayout2, screenHeightDp, localeScript, localeVariant, screenLayout2,
colorMode, isInvalid, size); colorMode, false, size);
} }
private char[] unpackLocaleOrRegion(byte in0, byte in1, char base) { private char[] unpackLocaleOrRegion(byte in0, byte in1, char base) {
......
...@@ -39,7 +39,7 @@ public class TestRedundantBrackets extends IntegrationTest { ...@@ -39,7 +39,7 @@ public class TestRedundantBrackets extends IntegrationTest {
} }
} }
public void method5(int a[], int n) { public void method5(int[] a, int n) {
a[1] = n * 2; a[1] = n * 2;
a[n - 1] = 1; a[n - 1] = 1;
} }
......
...@@ -13,7 +13,7 @@ import static org.hamcrest.MatcherAssert.assertThat; ...@@ -13,7 +13,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
public class TestAnnotations extends IntegrationTest { public class TestAnnotations extends IntegrationTest {
public static class TestCls { public static class TestCls {
private static @interface A { private @interface A {
int a(); int a();
} }
...@@ -29,7 +29,7 @@ public class TestAnnotations extends IntegrationTest { ...@@ -29,7 +29,7 @@ public class TestAnnotations extends IntegrationTest {
public void methodA3() { public void methodA3() {
} }
private static @interface V { private @interface V {
boolean value(); boolean value();
} }
...@@ -37,7 +37,7 @@ public class TestAnnotations extends IntegrationTest { ...@@ -37,7 +37,7 @@ public class TestAnnotations extends IntegrationTest {
public void methodV() { public void methodV() {
} }
private static @interface D { private @interface D {
float value() default 1.1f; float value() default 1.1f;
} }
......
...@@ -41,7 +41,7 @@ public class TestAnnotationsMix extends IntegrationTest { ...@@ -41,7 +41,7 @@ public class TestAnnotationsMix extends IntegrationTest {
assertTrue(ma.getAnnotations().length > 0); assertTrue(ma.getAnnotations().length > 0);
MyAnnotation a = (MyAnnotation) ma.getAnnotations()[0]; MyAnnotation a = (MyAnnotation) ma.getAnnotations()[0];
assertEquals(7, a.num()); assertEquals(7, a.num());
assertSame(a.state(), Thread.State.TERMINATED); assertSame(Thread.State.TERMINATED, a.state());
return true; return true;
} }
......
...@@ -8,7 +8,6 @@ import jadx.tests.api.IntegrationTest; ...@@ -8,7 +8,6 @@ import jadx.tests.api.IntegrationTest;
import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestTernary extends IntegrationTest { public class TestTernary extends IntegrationTest {
...@@ -18,12 +17,14 @@ public class TestTernary extends IntegrationTest { ...@@ -18,12 +17,14 @@ public class TestTernary extends IntegrationTest {
} }
public void test2(int a) { public void test2(int a) {
assertTrue(a == 3); checkTrue(a == 3);
} }
public int test3(int a) { public int test3(int a) {
return a > 0 ? a : (a + 2) * 3; return a > 0 ? a : (a + 2) * 3;
} }
private static void checkTrue(boolean v) {}
} }
@Test @Test
...@@ -33,7 +34,7 @@ public class TestTernary extends IntegrationTest { ...@@ -33,7 +34,7 @@ public class TestTernary extends IntegrationTest {
assertThat(code, not(containsString("else"))); assertThat(code, not(containsString("else")));
assertThat(code, containsString("return a != 2;")); assertThat(code, containsString("return a != 2;"));
assertThat(code, containsString("assertTrue(a == 3)")); assertThat(code, containsString("checkTrue(a == 3)"));
assertThat(code, containsString("return a > 0 ? a : (a + 2) * 3;")); assertThat(code, containsString("return a > 0 ? a : (a + 2) * 3;"));
} }
} }
...@@ -20,7 +20,7 @@ public class TestEnums3 extends IntegrationTest { ...@@ -20,7 +20,7 @@ public class TestEnums3 extends IntegrationTest {
private final int num; private final int num;
private Numbers(int n) { Numbers(int n) {
this.num = n; this.num = n;
} }
......
...@@ -24,7 +24,7 @@ public class TestEnums4 extends IntegrationTest { ...@@ -24,7 +24,7 @@ public class TestEnums4 extends IntegrationTest {
private final String[] exts; private final String[] exts;
private ResType(String... extensions) { ResType(String... extensions) {
this.exts = extensions; this.exts = extensions;
} }
......
...@@ -22,7 +22,7 @@ public class TestEnumsInterface extends IntegrationTest { ...@@ -22,7 +22,7 @@ public class TestEnumsInterface extends IntegrationTest {
public int apply(int x, int y) { public int apply(int x, int y) {
return x - y; return x - y;
} }
}; }
} }
public interface IOperation { public interface IOperation {
......
...@@ -7,7 +7,7 @@ import jadx.tests.api.IntegrationTest; ...@@ -7,7 +7,7 @@ import jadx.tests.api.IntegrationTest;
import static jadx.tests.api.utils.JadxMatchers.containsOne; import static jadx.tests.api.utils.JadxMatchers.containsOne;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertEquals;
public class TestInnerClass5 extends IntegrationTest { public class TestInnerClass5 extends IntegrationTest {
...@@ -83,8 +83,8 @@ public class TestInnerClass5 extends IntegrationTest { ...@@ -83,8 +83,8 @@ public class TestInnerClass5 extends IntegrationTest {
} }
public void check() throws Exception { public void check() throws Exception {
assertTrue(new I0().i().equals("i-i0i1i0i1i2i0i1i2i1i2i3i1i2i3a")); assertEquals("i-i0i1i0i1i2i0i1i2i1i2i3i1i2i3a", new I0().i());
assertTrue(i0.equals("i1")); assertEquals("i1", i0);
} }
} }
......
...@@ -21,6 +21,7 @@ public class TestSameMethodsNames extends IntegrationTest { ...@@ -21,6 +21,7 @@ public class TestSameMethodsNames extends IntegrationTest {
System.out.println("constructor"); System.out.println("constructor");
} }
@SuppressWarnings("MethodNameSameAsClassName")
void Bug() { void Bug() {
System.out.println("Bug"); System.out.println("Bug");
} }
......
...@@ -8,6 +8,7 @@ import jadx.tests.api.IntegrationTest; ...@@ -8,6 +8,7 @@ import jadx.tests.api.IntegrationTest;
import static jadx.tests.api.utils.JadxMatchers.containsOne; import static jadx.tests.api.utils.JadxMatchers.containsOne;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
public class TestTryCatchInIf extends IntegrationTest { public class TestTryCatchInIf extends IntegrationTest {
...@@ -33,7 +34,7 @@ public class TestTryCatchInIf extends IntegrationTest { ...@@ -33,7 +34,7 @@ public class TestTryCatchInIf extends IntegrationTest {
} }
public void check() { public void check() {
assertEquals(null, test("n", null)); assertNull(test("n", null));
assertEquals("n=7", test("n", "7")); assertEquals("n=7", test("n", "7"));
assertEquals("n=77", test("n", "0x" + Integer.toHexString(77))); assertEquals("n=77", test("n", "0x" + Integer.toHexString(77)));
assertEquals("Failed to parse number", test("n", "abc")); assertEquals("Failed to parse number", test("n", "abc"));
......
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