Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] JadxRuntimeException: Failed to find switch 'out' block #2246

Closed
pubiqq opened this issue Aug 12, 2024 · 1 comment
Closed

[core] JadxRuntimeException: Failed to find switch 'out' block #2246

pubiqq opened this issue Aug 12, 2024 · 1 comment
Labels
bug Core Issues in jadx-core module

Comments

@pubiqq
Copy link
Contributor

pubiqq commented Aug 12, 2024

Relevant log output or stacktrace

jadx.core.utils.exceptions.JadxRuntimeException: Failed to find switch 'out' block (already processed)
  at jadx.core.dex.visitors.regions.RegionMaker.calcSwitchOut(RegionMaker.java:924)
  at jadx.core.dex.visitors.regions.RegionMaker.processSwitch(RegionMaker.java:798)
  at jadx.core.dex.visitors.regions.RegionMaker.traverse(RegionMaker.java:157)
  at jadx.core.dex.visitors.regions.RegionMaker.makeRegion(RegionMaker.java:91)
  at jadx.core.dex.visitors.regions.RegionMaker.makeEndlessLoop(RegionMaker.java:411)
  at jadx.core.dex.visitors.regions.RegionMaker.processLoop(RegionMaker.java:201)
  at jadx.core.dex.visitors.regions.RegionMaker.traverse(RegionMaker.java:135)
  at jadx.core.dex.visitors.regions.RegionMaker.makeRegion(RegionMaker.java:91)
  at jadx.core.dex.visitors.regions.RegionMakerVisitor.visit(RegionMakerVisitor.java:52)

Provide sample and class/method full name

Test

package jadx.tests.integration.switches;

import jadx.tests.api.IntegrationTest;
import jadx.tests.api.utils.assertj.JadxAssertions;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

public class TestSwitchInLoop3 extends IntegrationTest {
    public static class TestCls {
        public int test(int k) {
            int a = 0;
            while (true) {
                int x = 0;  // <= the only difference from TestSwitchInLoop.java
                switch (k) {
                    case 0:
                        return a;
                    default:
                        a++;
                        k >>= 1;
                }
            }
        }

        public void check() {
            assertThat(test(1)).isEqualTo(1);
        }
    }

    @Test
    public void test() {
        JadxAssertions.assertThat(getClassNode(TestCls.class))
                .code()
                .containsOne("switch (k) {")
                .containsOne("case 0:")
                .containsOne("return a;")
                .containsOne("default:")
                .containsOne("a++;")
                .containsOne("k >>= 1;");
    }
}

Jadx version

1.5.0

@pubiqq pubiqq added bug Core Issues in jadx-core module labels Aug 12, 2024
@skylot
Copy link
Owner

skylot commented Aug 12, 2024

@pubiqq thank you for test case!
I commit a fix, but I don't think it is general enough to resolve similar cases. So if you find another simple case, fill free to share 🙂

Related issues: #2054, #826

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Core Issues in jadx-core module
Projects
None yet
Development

No branches or pull requests

2 participants