assert statement containing switch expression is not decompiled correctly
See original GitHub issueCFR version
CFR 0.151-SNAPSHOT (7b97993)
Compiler
javac 14.0.1
Description
assert
statements containing switch expressions (and maybe other complicated constructs as well) are not decompiled correctly. Instead of emitting an assert
, CFR emits a read of a variable called $assertionsDisabled
, which does not exist.
Example
Source:
class AssertTest {
void test(Integer i) {
assert switch (i + 1) {
case 1 -> true;
default -> false;
} : switch (i + 2) {
case 1 -> "1";
default -> "2";
};
}
void test2(int i) {
assert i != 2 : "Test";
}
}
Decompiled output:
class AssertTest {
AssertTest() {
}
void test(Integer n) {
if (!$assertionsDisabled) {
switch (n + 1) {
case 1: {
break;
}
default: {
throw new AssertionError((Object)(switch (n + 2) {
case 1 -> "1";
default -> "2";
}));
}
}
}
}
void test2(int n) {
assert (n != 2) : "Test";
}
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
switch statement not properly decompile · Issue #567 - GitHub
Original Code: namespace ILSpyBug { internal class Program { private static void Main(string[] args) { List list1 = new List (); List list2 ......
Read more >Why does an incomplete switch expression compile successfully
This is a known bug. See JDK-8212982 for details on its status. This code: public class SwitchBug { static String hold(String item) {...
Read more >CFR - yet another java decompiler. - benf.org
Fix for switch incorrectly marking some sources of break targets as breaks, leading to unstructured output. Fix for missing assert pattern (some cases...
Read more >Static Single Assignment for Decompilation
Copy statements inserted before the loop are not shown.111 ... 6.1 High level expressions for switch expressions in the Boomerang decompiler. . 199....
Read more >Switch Statements - RecStudio Decompiler Design
Expression propagation cannot remove the R1 register because it is used multiple times, but statement structuring can check if the expression has no...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
BTW - I used to get this one a little wrong, also fixed - but this produces amusing results in FF 😉
Oh, how gross is it that you can now write this: