Skip to content

Tighten requirements for auto-closeable beans #968

Description

@mkouba

The spec currently does not require the auto-closeable beans to implement the AutoCloseable interface, i.e. an auto-closeable bean is not required to define AutoCloseable in its set of bean types.

So a user can annotate any bean with @AutoClose but it's a NOOP unless it implements AutoCloseable.

Since @AutoClose makes no sense without AutoCloseable, it might be worth tightening the requirements and treat @AutoClose without AutoCloseable as a definition error. This could help users understand the purpose of the annotation.

I know that one argument against this requirement is more flexibility in producer methods:

@Produces
@AutoClose
public FooBar produce() {
    // FooBar is not AutoClosable -> NOOP is expected
    return someCondition ? new FooBar() : new CloseableFooBar();
}

But I'm not sure this flexibility is worth it. And it definitely makes no sense for class-based beans.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions