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.

`_` is not considered a keyword

See original GitHub issue

CFR version

0.149-SNAPSHOT (commit da9725ba)

Compiler

javac 11.0.5

Description

_ (underscore) is not considered a keyword even though it is one since Java 9 (JLS 3.9).

Renaming types, methods or fields should probably only be done when explicitly enabled. However local variable names (when compiled with -g:vars) should possibly always be renamed. Or both should be done based on the class file version?

Here (remove suffix .txt) is a class file which claims to be Java 11 (major 55, minor 0) but uses _ for a field and a local variable. Neither of them are renamed regardless of the --renameillegalidents value.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
leibnitz27commented, Apr 25, 2020

Oh that’s hilarious, I never pushed that. Whoops. Pushed now. Basically, acts as a easier way to override all the class file dependent options. (but will of course produce weird output if you try to be silly, like switch expressions in constructors, or take j10 string concatenation back to j6).

(and if you try to force v1 on a new class file, table sizes have changed, so BANG)

java org.benf.cfr.reader.Main SwitchTest30.class

/*
 * Decompiled with CFR <Could not determine version>.
 */
package org.benf.cfr.tests;

public class SwitchTest30 {
    public static void foo(String x) {
        System.out.println(switch (x) {
            case "Jennifer" -> throw new IllegalStateException();
            case "Alison", "Phillipa" -> {
                System.out.println("JIM");
                yield "JIM";
            }
            case "Sue", "Deborah", "Annabel" -> "FRED";
            default -> {
                if (x.length() > 4) {
                    yield "ALICE";
                }
                System.out.println("BOB!");
                yield "BOB";
            }
        });
    }

    public static void main(String ... args) {
        SwitchTest30.foo("Jennifer");
        SwitchTest30.foo("Sue");
        SwitchTest30.foo("Debbie");
    }
}

vs

java org.benf.cfr.reader.Main SwitchTest30.class --forceclassfilever j6

/*
 * Decompiled with CFR <Could not determine version>.
 */
package org.benf.cfr.tests;

public class SwitchTest30 {
    public static void foo(String x) {
        String string;
        String string2 = x;
        int n = -1;
        switch (string2.hashCode()) {
            case -1478439579: {
                if (!string2.equals("Jennifer")) break;
                n = 0;
                break;
            }
            case 1963877204: {
                if (!string2.equals("Alison")) break;
                n = 1;
                break;
            }
            case -1388868631: {
                if (!string2.equals("Phillipa")) break;
                n = 2;
                break;
            }
            case 83491: {
                if (!string2.equals("Sue")) break;
                n = 3;
                break;
            }
            case -1088790357: {
                if (!string2.equals("Deborah")) break;
                n = 4;
                break;
            }
            case 811978185: {
                if (!string2.equals("Annabel")) break;
                n = 5;
            }
        }
        switch (n) {
            case 0: {
                throw new IllegalStateException();
            }
            case 1:
            case 2: {
                System.out.println("JIM");
                string = "JIM";
                break;
            }
            case 3:
            case 4:
            case 5: {
                string = "FRED";
                break;
            }
            default: {
                if (x.length() > 4) {
                    string = "ALICE";
                    break;
                }
                System.out.println("BOB!");
                string = "BOB";
            }
        }
        System.out.println(string);
    }

    public static void main(String ... args) {
        SwitchTest30.foo("Jennifer");
        SwitchTest30.foo("Sue");
        SwitchTest30.foo("Debbie");
    }
0reactions
Marcono1234commented, Apr 24, 2020

unless a override version is set explicitly

Is that an option / feature already (sorry if I overlooked that) or are you planning to add that?

Read more comments on GitHub >

github_iconTop Results From Across the Web

C# - Ch. 1 Quiz Flashcards - Quizlet
What is NOT considered a keyword by the C# language? a) implicit b)global c)catch d)static. d. When writing C# code, how do you...
Read more >
What Are Keywords and How Do You Use Them? - Semrush
Important note: any term used in a search engine, whether a single word or a long phrase, is considered a keyword.
Read more >
List of Java keywords - Wikipedia
In the Java programming language, a keyword is any one of 67 reserved words that have a predefined meaning in the language. Because...
Read more >
Java Keywords - W3Schools
Java Reserved Keywords ... Note: true , false , and null are not keywords, but they are literals and reserved words that cannot...
Read more >
C Keywords and Identifiers - Programiz
Keywords are predefined, reserved words used in programming that have special meanings to the compiler. Keywords are part of the syntax and they...
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