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

Avoid using new FileInputStream / new FileOutputStream

    Details

    • Type: Improvement
    • Status: Closed (View Workflow)
    • Priority: Minor
    • Resolution: Fixed
    • Component/s: core
    • Labels:
      None
    • Similar Issues:

      Description

      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.

        Attachments

          Issue Links

            Activity

            stephenconnolly Stephen Connolly created issue -
            stephenconnolly Stephen Connolly made changes -
            Field Original Value New Value
            Remote Link This issue links to "PR#2816 (Web Link)" [ 15733 ]
            stephenconnolly Stephen Connolly made changes -
            Remote Link This issue links to "JDK-8080225 (Web Link)" [ 15734 ]
            stephenconnolly Stephen Connolly made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            stephenconnolly Stephen Connolly made changes -
            Status In Progress [ 3 ] In Review [ 10005 ]
            stephenconnolly Stephen Connolly made changes -
            Description 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.
            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.
            oleg_nenashev Oleg Nenashev made changes -
            Status In Review [ 10005 ] Resolved [ 5 ]
            Resolution Fixed [ 1 ]
            jonasatwork Jonas Jonsson made changes -
            Link This issue relates to JENKINS-45057 [ JENKINS-45057 ]
            stephenconnolly Stephen Connolly made changes -
            Link This issue is related to JENKINS-45903 [ JENKINS-45903 ]
            stephenconnolly Stephen Connolly made changes -
            Status Resolved [ 5 ] Closed [ 6 ]

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: