Skip to content

Commit

Permalink
fix: correct args shift for instance invoke-custom (#1816)
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Apr 16, 2023
1 parent 4230cd5 commit 3fa3e5a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
3 changes: 2 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 @@ -1014,9 +1014,10 @@ private void makeInlinedLambdaMethod(ICodeWriter code, InvokeCustomNode customNo
// force set external arg names into call method args
int extArgsCount = customNode.getArgsCount();
int startArg = customNode.getHandleType() == MethodHandleType.INVOKE_STATIC ? 0 : 1; // skip 'this' arg
int callArg = 0;
for (int i = startArg; i < extArgsCount; i++) {
RegisterArg extArg = (RegisterArg) customNode.getArg(i);
RegisterArg callRegArg = callArgs.get(i);
RegisterArg callRegArg = callArgs.get(callArg++);
callRegArg.getSVar().setCodeVar(extArg.getSVar().getCodeVar());
}
code.add(" -> {");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package jadx.tests.integration.java8;

import org.junit.jupiter.api.Test;

import jadx.tests.api.IntegrationTest;

import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat;

public class TestLambdaInstance2 extends IntegrationTest {

public static class TestCls {
private String field;

public Runnable test(String str, int i) {
return () -> call(str, i);
}

public void call(String str, int i) {
field = str + '=' + i;
}

public void check() throws Exception {
field = "";
test("num", 7).run();
assertThat(field).isEqualTo("num=7");
}
}

@Test
public void test() {
assertThat(getClassNode(TestCls.class))
.code()
.doesNotContain("lambda$")
.containsOne("call(str, i)");
}
}

0 comments on commit 3fa3e5a

Please sign in to comment.