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

Closeable.use throws NPE when block returns nullable #1450

Closed
05nelsonm opened this issue Mar 3, 2024 · 1 comment · Fixed by #1453
Closed

Closeable.use throws NPE when block returns nullable #1450

05nelsonm opened this issue Mar 3, 2024 · 1 comment · Fixed by #1453

Comments

@05nelsonm
Copy link
Contributor

05nelsonm commented Mar 3, 2024

block return type R is defined as <R>, not <R: Any>. If block produces null (e.g. Int?) and no exception is thrown, return will cause a KotlinNullPointerException.

A cast as R instead of a double banger is needed on result

image

@05nelsonm 05nelsonm changed the title Closable.use throws NPE whe block returns nullable Closable.use throws NPE when block returns nullable Mar 3, 2024
@05nelsonm
Copy link
Contributor Author

PR incoming tomorrow

@05nelsonm 05nelsonm changed the title Closable.use throws NPE when block returns nullable Closeable.use throws NPE when block returns nullable Mar 5, 2024
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

Successfully merging a pull request may close this issue.

1 participant