question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Handle eclipse special case string switch

See original GitHub issue

CFR version

6d817c99333c3f691aeb00aa68cb71047ecf359e

Compiler

OpenJDK 8

Description

Decompiler outputs too many labels for this simple code. Also seems like string switches are not decoded, even when the option is set to true.

    while (true) {
      switch (string) {
      case "apples":
        System.out.println("apples");
        break;
      case "pears":
        System.out.println("pears");
        break;
      }
    }

gets decompiled to

        block4: while (true) {
            block6: {
                String string = SwitchInLoop.string;
                switch (string.hashCode()) {
                    case -1411061671: {
                        if (string.equals("apples")) break;
                        continue block4;
                    }
                    case 106540109: {
                        if (!string.equals("pears")) {
                            continue block4;
                        }
                        break block6;
                    }
                }
                System.out.println("apples");
                continue;
            }
            System.out.println("pears");
        }

Example

apples-n-pears.jar.txt

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
GraxCodecommented, Jun 4, 2020

Again caused by me being lazy with the API, works now

1reaction
Marcono1234commented, Jun 4, 2020

@GraxCode, for the example jar file you provided with this issue or for a different class? For me the jar file decompiles fine.

Read more comments on GitHub >

github_iconTop Results From Across the Web

String in Switch Case in Java - GeeksforGeeks
It provides an easy way to dispatch execution to different parts of code based on the value of the expression. Basically, the expression...
Read more >
The switch Statement (The Java™ Tutorials > Learning the ...
A switch works with the byte , short , char , and int primitive data types. It also works with enumerated types (discussed...
Read more >
Compiler error for string switch case label - java - Stack Overflow
The whole case label statement is marked in red line by eclipse "case PreferenceType.FIRST.toString():" and when I hover the mouse over the case...
Read more >
Java Switch Statement With Strings (With and Without break)
Learn how switch statements work in java with a step-by-step example using strings and how the break statement affects the flow of execution ......
Read more >
Java12/Examples - Eclipsepedia
Switch expression, Enhanced switch statement and Multi-constant case labels are Preview features in Java 12. They are not enabled by default and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found