-
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: additional checks for 'if' blocks inside loops (#809)
- Loading branch information
Showing
5 changed files
with
112 additions
and
1 deletion.
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
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
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
47 changes: 47 additions & 0 deletions
47
jadx-core/src/test/java/jadx/tests/integration/loops/TestDoWhileBreak2.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,47 @@ | ||
package jadx.tests.integration.loops; | ||
|
||
import java.util.Arrays; | ||
import java.util.Iterator; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import jadx.tests.api.IntegrationTest; | ||
|
||
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; | ||
|
||
public class TestDoWhileBreak2 extends IntegrationTest { | ||
|
||
public static class TestCls { | ||
Iterator<String> it; | ||
|
||
@SuppressWarnings("ConstantConditions") | ||
public Object test() { | ||
String obj; | ||
do { | ||
obj = this.it.next(); | ||
if (obj == null) { | ||
return obj; // 'return null' works | ||
} | ||
} while (this.it.hasNext()); | ||
return obj; | ||
} | ||
|
||
public void check() { | ||
this.it = Arrays.asList("a", "b").iterator(); | ||
assertThat(test()).isEqualTo("b"); | ||
|
||
this.it = Arrays.asList("a", "b", null).iterator(); | ||
assertThat(test()).isEqualTo(null); | ||
} | ||
} | ||
|
||
@Test | ||
public void test() { | ||
assertThat(getClassNode(TestCls.class)) | ||
.code() | ||
.containsLine(2, "do {") | ||
.containsLine(3, "obj = this.it.next();") | ||
.containsLine(3, "if (obj == null) {") | ||
.containsLine(2, "} while (this.it.hasNext());"); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
jadx-core/src/test/java/jadx/tests/integration/loops/TestDoWhileBreak3.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,33 @@ | ||
package jadx.tests.integration.loops; | ||
|
||
import java.util.Iterator; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import jadx.NotYetImplemented; | ||
import jadx.tests.api.IntegrationTest; | ||
|
||
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; | ||
|
||
public class TestDoWhileBreak3 extends IntegrationTest { | ||
|
||
public static class TestCls { | ||
Iterator<String> it; | ||
|
||
public void test() { | ||
do { | ||
if (!it.hasNext()) { | ||
break; | ||
} | ||
} while (it.next() != null); | ||
} | ||
} | ||
|
||
@NotYetImplemented | ||
@Test | ||
public void test() { | ||
assertThat(getClassNode(TestCls.class)) | ||
.code() | ||
.containsOnlyOnce("while"); | ||
} | ||
} |