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] [primitive pattern][preview] Wrong NPE thrown by code with instanceof and record pattern #3536

Open
jarthana opened this issue Jan 9, 2025 · 1 comment
Milestone

Comments

@jarthana
Copy link
Member

jarthana commented Jan 9, 2025

The following code compiles fine, but throws an NPE when run:

record Record(Byte b) {}
public class X {
	public static void main(String argv[]) {
		X x = new X();
		System.out.println(x.foo(new Record(null)));
	}
	public int foo(Record r) {
		int result = 0;
		result = r instanceof Record(short s) ? 0 : 1;
		return result;
	}
}

Inspecting the produced output, I find this strange lines which is causing the issue:

        10: checkcast     #23                 // class Record
        13: invokevirtual #41                 // Method Record.i:()Ljava/lang/Byte;
        16: invokevirtual #45                 // Method java/lang/Byte.byteValue:()B
@jarthana jarthana added this to the BETA_JAVA24 milestone Jan 9, 2025
@mpalat
Copy link
Contributor

mpalat commented Jan 9, 2025

Will take a look

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