-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: don't override type of method parameter in const deboxing (#723)
- Loading branch information
Showing
3 changed files
with
127 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
jadx-core/src/test/java/jadx/tests/integration/others/TestDeboxing2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package jadx.tests.integration.others; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import jadx.core.dex.nodes.ClassNode; | ||
import jadx.tests.api.IntegrationTest; | ||
|
||
import static jadx.tests.api.utils.JadxMatchers.containsOne; | ||
import static jadx.tests.api.utils.JadxMatchers.countString; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
public class TestDeboxing2 extends IntegrationTest { | ||
|
||
public static class TestCls { | ||
public long test(Long l) { | ||
if (l == null) { | ||
l = 0L; | ||
} | ||
return l; | ||
} | ||
|
||
public void check() { | ||
assertThat(test(null), is(0L)); | ||
assertThat(test(0L), is(0L)); | ||
assertThat(test(7L), is(7L)); | ||
} | ||
} | ||
|
||
@Test | ||
public void test() { | ||
noDebugInfo(); | ||
|
||
ClassNode cls = getClassNode(TestCls.class); | ||
String code = cls.getCode().toString(); | ||
|
||
assertThat(code, containsOne("long test(Long l)")); | ||
assertThat(code, containsOne("if (l == null) {")); | ||
assertThat(code, containsOne("l = 0L;")); | ||
|
||
// checks for 'check' method | ||
assertThat(code, containsOne("test(null)")); | ||
assertThat(code, containsOne("test(0L)")); | ||
assertThat(code, countString(2, "is(0L)")); | ||
assertThat(code, containsOne("test(7L)")); | ||
assertThat(code, containsOne("is(7L)")); | ||
|
||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
jadx-core/src/test/java/jadx/tests/integration/others/TestDeboxing3.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package jadx.tests.integration.others; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import jadx.NotYetImplemented; | ||
import jadx.core.dex.nodes.ClassNode; | ||
import jadx.tests.api.IntegrationTest; | ||
|
||
import static jadx.tests.api.utils.JadxMatchers.containsOne; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
public class TestDeboxing3 extends IntegrationTest { | ||
|
||
public static class TestCls { | ||
|
||
public static class Pair<F, S> { | ||
public F first; | ||
public S second; | ||
} | ||
|
||
private Map<String, Pair<Long, String>> cache = new HashMap<>(); | ||
|
||
public boolean test(String id, Long l) { | ||
if (l == null) { | ||
l = 900000L; | ||
} | ||
Pair<Long, String> pair = this.cache.get(id); | ||
if (pair == null) { | ||
return false; | ||
} | ||
return pair.first + l > System.currentTimeMillis(); | ||
} | ||
} | ||
|
||
@Test | ||
public void test() { | ||
noDebugInfo(); | ||
|
||
ClassNode cls = getClassNode(TestCls.class); | ||
String code = cls.getCode().toString(); | ||
|
||
assertThat(code, containsOne("l = 900000L;")); | ||
} | ||
|
||
@Test | ||
@NotYetImplemented("Full deboxing and generics propagation") | ||
public void testFull() { | ||
noDebugInfo(); | ||
|
||
ClassNode cls = getClassNode(TestCls.class); | ||
String code = cls.getCode().toString(); | ||
|
||
assertThat(code, containsOne("Pair<Long, String> pair = this.cache.get(id);")); | ||
assertThat(code, containsOne("return pair.first + l > System.currentTimeMillis();")); | ||
|
||
} | ||
} |