Repository navigation
[java] Model RandomAccessFile reads and writes for Pulse resource leaks - #2286
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
RandomAccessFileconstructors are modeled as allocating a resource, but its read, write and seek methods were not. Calling any of them (for examplelength(),readFully()orseek()) 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 testFN_readInstallationFileBadinResourceLeaks.javashows this.RandomAccessFileread/write/seek methods (length,read*,write*,seek,setLength,skipBytes,getFilePointer,getFD) as calls that may throwIOExceptionand do not close the file, in the same way as the existingInputStreamandWritermodels.Tests in
ResourceLeaks.java:readInstallationFileBad(previouslyFN_),randomAccessFileNotClosedAfterLengthBadandrandomAccessFileNotClosedOnWriteExceptionBad, plusrandomAccessFileClosedAfterWriteOk(closed infinally). The existingreadInstallationFileOkstays clean.Test plan
Badmethods is reportedPULSE_RESOURCE_LEAKfor the 3Badmethods; theOkcases stay cleanmake direct_java_pulse_test: no other change inResourceLeaks.javaresults. The only other differences on my machine are lambda names inInvokeDynamic.javaandTransitiveAccess.java(JDK 21 javac), which are the same with and without this change.