Skip to content

Enforce @MustBeClosed on method and constructor references. - #6259

Open
copybara-service[bot] wants to merge 1 commit into
masterfrom
test_1009886326
Open

copybara-service[bot] wants to merge 1 commit into
masterfrom
test_1009886326

Conversation

@copybara-service

Copy link
Copy Markdown
Contributor

Enforce @MustBeClosed on method and constructor references.

MustBeClosedChecker only checked method invocations and constructor calls, so
passing a reference to a @MustBeClosed method or constructor (such as
foo::mustBeClosedMethod or MustBeClosedResource::new) to a functional
interface whose method is not annotated with @MustBeClosed (such as
Supplier<Closeable>) bypassed the check and let the resource leak.

Method and constructor references are now checked like lambdas: they are
reported unless the functional interface method is annotated with
@MustBeClosed. As with lambdas, references passed to exception-testing APIs
such as assertThrows are exempt. StreamResourceLeak shares this logic, so it
now also reports references such as Files::lines. The new behavior can be
disabled with -XepOpt:MustBeClosedChecker:MatchMethodReferences=false.

MustBeClosedChecker only checked method invocations and constructor calls, so
passing a reference to a `@MustBeClosed` method or constructor (such as
`foo::mustBeClosedMethod` or `MustBeClosedResource::new`) to a functional
interface whose method is not annotated with `@MustBeClosed` (such as
`Supplier<Closeable>`) bypassed the check and let the resource leak.

Method and constructor references are now checked like lambdas: they are
reported unless the functional interface method is annotated with
`@MustBeClosed`. As with lambdas, references passed to exception-testing APIs
such as `assertThrows` are exempt. StreamResourceLeak shares this logic, so it
now also reports references such as `Files::lines`. The new behavior can be
disabled with `-XepOpt:MustBeClosedChecker:MatchMethodReferences=false`.

PiperOrigin-RevId: 1009886326

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant