Skip to content

Conversation

@parameshn
Copy link

@parameshn parameshn commented Jan 22, 2026

Add MustCall annotations to core JDBC, MIDI, and audio interfaces that own native or external resources.
These annotations model required close() obligations and propagate correctly to all subinterfaces, enabling the MustCall Checker to detect resource leaks.

Related to typetools/checker-framework#6354.

This ensures that close() obligations are enforced consistently and propagate to all subinterfaces such as Mixer, SourceDataLine, and TargetDataLine, without requiring redundant annotations on each subtype.

Audio Lines own native system resources; failing to call close() leaks OS-level audio handles. Annotating Line enforces this lifecycle and correctly propagates to all subtypes.
Closing a MidiDevice:

-releases native MIDI resources
-stops internal threads
-automatically closes all associated transmitters and receivers

Indicates that the application has finished using the receiver, and that limited resources it requires may be released or made available.
Closing a MidiDevice:
 -releases native MIDI resources
-stops internal threads
-automatically closes all associated transmitters and receivers Indicates that the application has finished using the receiver, and that limited resources it requires may be released or made available.
All ResultSet and RowSet implementations, both connected and disconnected, should be explicitly closed. Connected types release live database resources such as connections and cursors, while disconnected types still hold internal resources that should not be left to garbage collection, especially in long running applications.
Copy link

@msridhar msridhar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of quick comments. Also, I think we probably want to have a corresponding PR in typetools/checker-framework with tests for these changes. To do that properly, see here for instructions.

Also, looks like WPI tests are failing. @kelloggm any idea how to debug that?

Comment on lines +100 to +101
@AnnotatedFor({"mustcall"})
@InheritableMustCall("close")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the Javadoc, I think we may need @NotOwning annotations on methods like MidiSystem#getReceiver and MidiSystem#getTransmitter, to indicate that the MidiDevice returned by those APIs does not need to be explicitly closed. Do you agree?

Copy link
Author

@parameshn parameshn Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my understanding, when MidiSystem.getReceiver() / getTransmitter() are used, the underlying MidiDevice is opened implicitly by the system and closed implicitly when the returned Receiver / Transmitter is closed (assuming no other Receivers/Transmitters remain open). As a result, the application does not own the MidiDevice; its responsibility is only to close the returned Receiver / Transmitter. Since the MidiDevice is not exposed by these APIs, there isn’t really a place to annotate it with @NotOwning at the API level.

// Requests a Receiver from the system.
// Implicitly opens the underlying MidiDevice
        Receiver receiver = MidiSystem.getReceiver();

// Closes the Receiver.
 // Implicitly closes the MidiDevice (if this was the last open one)
        receiver.close();

* @since 1.3
*/
@AnnotatedFor({"mustcall"})
@InheritableMustCall("close")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a Line object automatically open at the time it is constructed, is an explicit open() call required? If it's the latter, we might need to treat Line like Socket and add a @CreatesMustCallFor annotation somewhere. This might be tricky since Line is an interface.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s the latter: a Line is not automatically open when obtained, and an explicit open() call is required.
Given that Line is an interface with multiple implementations and open(...) variants, annotating Line itself seems likely to be too coarse and incomplete. I think a similar argument applies to MidiDevice as well, since it is also an interface and can be opened both explicitly and implicitly. I’d appreciate your thoughts on whether there’s a better way to model this.

@kelloggm
Copy link

WPI tests are failing for JDKs 11 and 17 only (but not 21 and 25) because of changes upstream; the CF itself only runs the WPI tests on the latest LTS JDK now, and they're not supported for older JDKs. The particular problem is that the build scripts used by the target projects use -Xlint:all,-processing,-this-escape; the -this-escape xlint option is present in the Java 21 docs but not in the Java 17 docs. So, the right change is probably to disable the WPI tests for Java 11/17 entirely on this repo.

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 this pull request may close these issues.

3 participants