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.

Code is moved out of default case of switch

See original GitHub issue

CFR version

0.150-SNAPSHOT (commit cf242d2)

Compiler

  • javac 11.0.5
  • javac 14

Description

Relates to #128

Code in the default case of a switch statement or expression with no other cases (or fall-through to default) is moved outside the switch. This is sometimes not possible, e.g. when the default case defines a local class with the same name.

Source:

class SwitchExpressionLocalClass {
    void test() {
        switch(0) {
            default: {
                class Test {
                    Test(int i) { }
                }
                
                new Test(1);
            }
        };
        class Test { }
        new Test();
    }
}

Decompiled output:

class SwitchExpressionLocalClass {
    SwitchExpressionLocalClass() {
    }

    /*
     * Inner class renamed, behaviour may change
     * Enabled force condition propagation
     * Lifted jumps to return sites
     */
    void test() {
        switch (0) {
            default: 
        }
        class Test_1 {
            Test_1(int n) {
            }
        }
        new Test_1(1);
        class Test {
            Test() {
            }
        }
        new Test();
    }
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
Marcono1234commented, Mar 22, 2020

Yeah, I briefly looked at the byte code and noticed that it does not provide the necessary information to easily tell where the local class is declared. So I am perfectly fine with you considering this a “never fix” (and closing this issue).

Thanks for letting me know that the process will be reduced. Apparently you have had a pretty long commute based on the amount of work you have put into this 😄 Stay well 😃

1reaction
leibnitz27commented, Apr 19, 2020

As discussed - this isn’t going to be fixed, apart from the cases (like #128) where it’s possible to know which form must be required. (and the fix for #128 is fairly heavy handed, so I’m keen not to use it generally 😉 )

Read more comments on GitHub >

github_iconTop Results From Across the Web

Should switch statements always contain a default clause?
Leaving out the default case enables the compiler to optionally warn or fail when it sees an unhandled case. Static verifiability is after...
Read more >
The Great Debate: Always Include a Default Case in Switch?
As stated above, it is not mandatory to declare the default clause in a switch statement. It is entirely optional. Without it, the...
Read more >
Switch statements: `default` doesn't have to be the last case
Non-last `default` cases are confusing but perfectly valid. Sometimes it makes sense to place them at the beginning or in the middle.
Read more >
[java] MissingBreakInSwitch - last default case does not ...
Description: A switch statement does not contain a break, even if it is the default case. Code Sample demonstrating the issue: https://www.
Read more >
Is it necessary to add the default case while using switch cases?
If this is the case, I think you are asked to add a default case , because it is an accepted coding style,...
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