Skip to content

Commit

Permalink
core: select correct array type element
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Dec 25, 2013
1 parent 5cbf71b commit 6bac5c1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
6 changes: 5 additions & 1 deletion jadx-core/src/main/java/jadx/core/codegen/InsnGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,11 @@ private void fillArray(FillArrayNode insn, CodeWriter code) throws CodegenExcept
ArgType elType = insn.getElementType();
if (!elType.equals(insnElementType) && !insnArrayType.equals(ArgType.OBJECT)) {
ErrorsCounter.methodError(mth,
"Incorrect type for fill-array insn " + InsnUtils.formatOffset(insn.getOffset()));
"Incorrect type for fill-array insn " + InsnUtils.formatOffset(insn.getOffset())
+ ", element type: " + elType + ", insn element type: " + insnElementType);
if (!elType.isTypeKnown()) {
elType = insnElementType.isTypeKnown() ? insnElementType : elType.selectFirst();
}
}
StringBuilder str = new StringBuilder();
Object data = insn.getData();
Expand Down
39 changes: 39 additions & 0 deletions jadx-core/src/test/java/jadx/tests/internal/TestTmp2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package jadx.tests.internal;

import jadx.api.InternalJadxTest;
import jadx.core.dex.nodes.ClassNode;

import org.junit.Test;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;

public class TestTmp2 extends InternalJadxTest {

public static class TestCls extends Exception {
int c;
String d;
String f;

public void testComplexIf(String a, int b) {
if (d == null || (c == 0 && b != -1 && d.length() == 0)) {
c = a.codePointAt(c);
} else {
if (a.hashCode() != 0xCDE) {
c = f.compareTo(a);
}
}
}
}

@Test
public void test() {
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();
System.out.println(code);

assertThat(code, containsString("return;"));
assertThat(code, not(containsString("else")));
}
}

0 comments on commit 6bac5c1

Please sign in to comment.