-
Improvement
-
Resolution: Fixed
-
Minor
-
None
See https://bugs.openjdk.java.net/browse/JDK-8080225
Basically, FileInputStream and FileOutputStream both use a finalizer to ensure that the resources are closed.
Even with programmers do call close() after using FileInputStream, its finalize() method will still be called. In other words, still get the side effect of the FinalReference being registered at FileInputStream allocation time, and also reference processing to reclaim the FinalReference during GC (any GC solution has to deal with this).
The recommended solution is to switch to Files.newInputStream and Files.newOutputStream respectively as these use a reference queue to clean up unclosed streams that are eligible for GC rather than waiting for a finalizer always.
- is related to
-
JENKINS-45903 transient file handle leak in LargeText.GzipAwareSession.isGzipStream(File)
-
- Resolved
-
- relates to
-
JENKINS-45057 "too many files open": file handles leak, job output file not closed
-
- Resolved
-
- links to
[JENKINS-42934] Avoid using new FileInputStream / new FileOutputStream
Remote Link | New: This issue links to "PR#2816 (Web Link)" [ 15733 ] |
Remote Link | New: This issue links to "JDK-8080225 (Web Link)" [ 15734 ] |
Status | Original: Open [ 1 ] | New: In Progress [ 3 ] |
Status | Original: In Progress [ 3 ] | New: In Review [ 10005 ] |
Description |
Original:
See [https://bugs.openjdk.java.net/browse/JDK-8080225] Basically, {{FileInputStream}} and {{FileOutputStream}} bothe use a {{finalizer}} to ensure that the resources are closed. Even with programmers do call {{close()}} after using {{FileInputStream}}, its {{finalize()}} method will still be called. In other words, still get the side effect of the {{FinalReference}} being registered at {{FileInputStream}} allocation time, and also reference processing to reclaim the {{FinalReference}} during GC (any GC solution has to deal with this). The recommended solution is to switch to {{Files.newInputStream}} and {{Files.newOutputStream}} respectively as these use a reference queue to clean up *unclosed* streams that are eligible for GC rather than waiting for a finalizer always. |
New:
See [https://bugs.openjdk.java.net/browse/JDK-8080225] Basically, {{FileInputStream}} and {{FileOutputStream}} both use a {{finalizer}} to ensure that the resources are closed. Even with programmers do call {{close()}} after using {{FileInputStream}}, its {{finalize()}} method will still be called. In other words, still get the side effect of the {{FinalReference}} being registered at {{FileInputStream}} allocation time, and also reference processing to reclaim the {{FinalReference}} during GC (any GC solution has to deal with this). The recommended solution is to switch to {{Files.newInputStream}} and {{Files.newOutputStream}} respectively as these use a reference queue to clean up *unclosed* streams that are eligible for GC rather than waiting for a finalizer always. |
Code changed in jenkins
User: Stephen Connolly
Path:
cli/src/main/java/hudson/cli/PrivateKeyProvider.java
core/src/main/java/hudson/ClassicPluginStrategy.java
core/src/main/java/hudson/FilePath.java
core/src/main/java/hudson/FileSystemProvisioner.java
core/src/main/java/hudson/Main.java
core/src/main/java/hudson/PluginWrapper.java
core/src/main/java/hudson/Util.java
core/src/main/java/hudson/WebAppMain.java
core/src/main/java/hudson/XmlFile.java
core/src/main/java/hudson/lifecycle/WindowsInstallerLink.java
core/src/main/java/hudson/model/FileParameterValue.java
core/src/main/java/hudson/model/Queue.java
core/src/main/java/hudson/model/Run.java
core/src/main/java/hudson/model/UpdateCenter.java
core/src/main/java/hudson/tools/JDKInstaller.java
core/src/main/java/hudson/util/AtomicFileWriter.java
core/src/main/java/hudson/util/CompressedFile.java
core/src/main/java/hudson/util/IOUtils.java
core/src/main/java/hudson/util/SecretRewriter.java
core/src/main/java/hudson/util/StreamTaskListener.java
core/src/main/java/hudson/util/TextFile.java
core/src/main/java/hudson/util/io/ReopenableFileOutputStream.java
core/src/main/java/hudson/util/io/RewindableFileOutputStream.java
core/src/main/java/hudson/util/io/TarArchiver.java
core/src/main/java/hudson/util/io/ZipArchiver.java
core/src/main/java/jenkins/diagnosis/HsErrPidList.java
core/src/main/java/jenkins/security/DefaultConfidentialStore.java
core/src/main/java/jenkins/util/AntClassLoader.java
core/src/main/java/jenkins/util/JSONSignatureValidator.java
core/src/main/java/jenkins/util/VirtualFile.java
core/src/main/java/jenkins/util/io/FileBoolean.java
core/src/main/java/jenkins/util/xml/XMLUtils.java
core/src/test/java/hudson/FilePathTest.java
core/src/test/java/hudson/PluginManagerTest.java
core/src/test/java/hudson/UtilTest.java
core/src/test/java/hudson/model/LoadStatisticsTest.java
core/src/test/java/hudson/os/SUTester.java
core/src/test/java/hudson/util/io/TarArchiverTest.java
core/src/test/java/hudson/util/io/ZipArchiverTest.java
test/src/test/java/hudson/model/DirectoryBrowserSupportTest.java
test/src/test/java/hudson/tools/JDKInstallerTest.java
http://jenkins-ci.org/commit/jenkins/f0cd7ae8ff269dd738e3377a62f3fbebebf9aef6
Log:
JENKINS-42934Avoid using new FileInputStream / new FileOutputStream