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

[24] ECJ generates wrong code for primitive pattern with instanceof #3535

Open
jarthana opened this issue Jan 9, 2025 · 2 comments
Open
Assignees

Comments

@jarthana
Copy link
Member

jarthana commented Jan 9, 2025

Given the code,

	static Integer getInteger() {
		return Integer.MIN_VALUE;
	}
	public int foo() {
		Y<Integer> f = new Y<>();
		f.put(X.getInteger()); // This makes all the difference
		return f.get() instanceof float ? 3 : 2;
	}

Compiled and run, this returns 3 with ECJ but returns 2 with Javac. Inspecting the compiled output, I see this from ECJ:
19: instanceof #3 // class java/lang/Object

which I believe is wrong. With Javac, it's Integer.

BTW, Y is defined as below:

class Y<T> {
    T a;
    T get() {
        return a;
    }
    void put(T val) {
        a= val;
    }
}
@mpalat
Copy link
Contributor

mpalat commented Jan 9, 2025

I will take a look

@mpalat
Copy link
Contributor

mpalat commented Jan 22, 2025

Finally got to this. javac differed earlier -Compiling with Java 24 at EA23 version where this is different and a EA27 version onwards where this result is 3 now as per ECJ behaviour. The above patch is only a unit test case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants