Skip to content

[java] Model RandomAccessFile reads and writes for Pulse resource leaks - #2286

Merged
dulmarod merged 1 commit into
meta:mainfrom
tanvir-ux:fix/pulse-randomaccessfile-usage
Oct 28, 2026
Merged

dulmarod merged 1 commit into
meta:mainfrom
tanvir-ux:fix/pulse-randomaccessfile-usage

Conversation

@tanvir-ux

Copy link
Copy Markdown
Contributor

Summary

RandomAccessFile constructors are modeled as allocating a resource, but its read, write and seek methods were not. Calling any of them (for example length(), readFully() or seek()) made Pulse stop tracking the file, so a file that is left open when one of those calls throws, or that is never closed at all, was not reported. The existing test FN_readInstallationFileBad in ResourceLeaks.java shows this.

  • Model the RandomAccessFile read/write/seek methods (length, read*, write*, seek, setLength, skipBytes, getFilePointer, getFD) as calls that may throw IOException and do not close the file, in the same way as the existing InputStream and Writer models.

Tests in ResourceLeaks.java: readInstallationFileBad (previously FN_), randomAccessFileNotClosedAfterLengthBad and randomAccessFileNotClosedOnWriteExceptionBad, plus randomAccessFileClosedAfterWriteOk (closed in finally). The existing readInstallationFileOk stays clean.

Test plan

  • Before (main @ cb4fcf8, with the new tests): none of the 3 Bad methods is reported
  • After: PULSE_RESOURCE_LEAK for the 3 Bad methods; the Ok cases stay clean
  • make direct_java_pulse_test: no other change in ResourceLeaks.java results. The only other differences on my machine are lambda names in InvokeDynamic.java and TransitiveAccess.java (JDK 21 javac), which are the same with and without this change.

RandomAccessFile constructors allocate a resource, but calls such as
length(), readFully() or seek() were not modeled. Any of them made Pulse
stop tracking the file, so a file left open when one of those calls
throws, or never closed at all, was not reported
(FN_readInstallationFileBad).

Model the RandomAccessFile read, write and seek methods as calls that
may throw IOException and do not close the file.
@meta-cla meta-cla Bot added the CLA Signed label Oct 28, 2026
@dulmarod
dulmarod merged commit 1e90289 into meta:main Oct 28, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants