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

Nullness checker inside if expression inside a lambda not working correctly #6963

Open
theit opened this issue Jan 22, 2025 · 0 comments
Open
Assignees

Comments

@theit
Copy link

theit commented Jan 22, 2025

Checker Framework 3.48.4
Java 21

I have the following snippet inside my code:

private @Nullable ProxyData proxyData;

static class ProxyData {
	private @Nullable String host;
	private int port;
	private @Nullable String username;
	private @Nullable String password;
}

this.proxyData is later processed inside a lambda expression in the following method:

private void doProxyConfiguration() {
	executeMenu(() -> {
		System.out.println("Actual proxy configuration:");
		if (null != this.proxyData) {
			System.out.println("- Host:     " + this.proxyData.host);
			System.out.println("- Port:     " + this.proxyData.port);
			System.out.println("- Username: " + this.proxyData.username);
			System.out.println("- Passwort: " + this.proxyData.password);
		} else {
			System.out.println("- no proxy configured!");
		}
	}, //
	...
}

Checkerframework now complains in my Maven build that access to this.proxyData.port/username/password in the if expression deference a possibly-null reference this.proxyData:

(...)
[INFO] Compiling 8 source files with javac [forked debug release 21 module-path] to target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] ...\MyClass.java:[326,44] Fehler: [dereference.of.nullable] dereference of possibly-null reference this.proxyData
[ERROR] ...\MyClass.java:[327,44] Fehler: [dereference.of.nullable] dereference of possibly-null reference this.proxyData
[ERROR] ...\MyClass.java:[328,44] Fehler: [dereference.of.nullable] dereference of possibly-null reference this.proxyData
[INFO] 3 errors
(...)

This shouldn't happen because a) there's an explicit check for !=null, and b) the erroneous lines happen after this.proxyData.host is accessed.

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