Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-42934

Avoid using new FileInputStream / new FileOutputStream

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Minor Minor
    • core
    • 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.

          [JENKINS-42934] Avoid using new FileInputStream / new FileOutputStream

          Stephen Connolly created issue -
          Stephen Connolly made changes -
          Remote Link New: This issue links to "PR#2816 (Web Link)" [ 15733 ]
          Stephen Connolly made changes -
          Remote Link New: This issue links to "JDK-8080225 (Web Link)" [ 15734 ]
          Stephen Connolly made changes -
          Status Original: Open [ 1 ] New: In Progress [ 3 ]
          Stephen Connolly made changes -
          Status Original: In Progress [ 3 ] New: In Review [ 10005 ]
          Stephen Connolly made changes -
          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-42934 Avoid using new FileInputStream / new FileOutputStream

          SCM/JIRA link daemon added a comment - 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-42934 Avoid using new FileInputStream / new FileOutputStream

          Code changed in jenkins
          User: Stephen Connolly
          Path:
          core/src/main/java/hudson/util/io/RewindableFileOutputStream.java
          http://jenkins-ci.org/commit/jenkins/a7fc5701584bc28cd34fc3f018cc107616f7cd9a
          Log:
          JENKINS-42934 Need to catch a different exception

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Stephen Connolly Path: core/src/main/java/hudson/util/io/RewindableFileOutputStream.java http://jenkins-ci.org/commit/jenkins/a7fc5701584bc28cd34fc3f018cc107616f7cd9a Log: JENKINS-42934 Need to catch a different exception

          Code changed in jenkins
          User: Stephen Connolly
          Path:
          core/src/main/java/hudson/util/io/RewindableFileOutputStream.java
          http://jenkins-ci.org/commit/jenkins/211bb293381802f7c653c6e6cee965ab316d0fc4
          Log:
          JENKINS-42934 When you specify options you need to include CREATE or the file will not be created

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Stephen Connolly Path: core/src/main/java/hudson/util/io/RewindableFileOutputStream.java http://jenkins-ci.org/commit/jenkins/211bb293381802f7c653c6e6cee965ab316d0fc4 Log: JENKINS-42934 When you specify options you need to include CREATE or the file will not be created

          Code changed in jenkins
          User: Stephen Connolly
          Path:
          core/src/test/java/hudson/UtilTest.java
          http://jenkins-ci.org/commit/jenkins/218d0a55169aa030646e4f7a0469e9ce8fe2c93f
          Log:
          JENKINS-42934 Actually use Java's file locking API to lock the file on windows

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Stephen Connolly Path: core/src/test/java/hudson/UtilTest.java http://jenkins-ci.org/commit/jenkins/218d0a55169aa030646e4f7a0469e9ce8fe2c93f Log: JENKINS-42934 Actually use Java's file locking API to lock the file on windows

            stephenconnolly Stephen Connolly
            stephenconnolly Stephen Connolly
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: