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

CFR may perform incorrect modifications to the type of generic class variables #338

Open
xxh160 opened this issue Apr 24, 2023 · 0 comments
Labels

Comments

@xxh160
Copy link

xxh160 commented Apr 24, 2023

Hi! I am doing some research based on CFR, and I found a bug related to CFR's incorrect modifications to the type of generic class variables.

I have tested this issue with several code samples, and here is an example:

class Demo1<T extends Character, N> {
    public final Short foo(T t1) {
        final Boolean b = false;
        T t2 = t1;
        T t3 = (T) new Character('x');
        N n = (N) new String("");
        return foo(((b) ? t3 : t2));
    }
}

After decompiling with CFR, the type of t3 and n were modified:

/*
 * Decompiled with CFR 0.153-SNAPSHOT (24c7433-dirty).
 */
class Demo1<T extends Character, N> {
    Demo1() {
    }
    public final Short foo(T t) {
        Boolean bl = false;
        T t2 = t;
        Character c = new Character('x');
        String string = new String("");
        return this.foo(bl != false ? c : t2);
    }
}

When I tried to compile the decompiled code, a compilation error occurred:

./Demo1.java:13: error: incompatible types: bad type in conditional expression
        return this.foo(bl != false ? c : t2);
                                      ^
    Character cannot be converted to T
  where T is a type-variable:
    T extends Character declared in class Demo1
Note: ./Demo1.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error

Would you please have a look at this? It is important for me!
Thanks a lot!

CFR version: CFR 0.153-SNAPSHOT (24c7433-dirty).
Javac version: openjdk 11.0.18 2023-01-17.
I also attach the source files and the decompilation results and I hope they will be helpful: demo.zip.

@xxh160 xxh160 added the bug label Apr 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant