Skip to content

[JENKINS-49971] hudson.Util.loadFile() has a race condition #22627

Closed

Description

@jenkins-infra-bot

Util.loadFile() first checks if the file exists via File.exists(). It then tries to open the file for reading. However, it is possible for the file to be deleted between the existence check and the file-open operation, in which case the method throws a FileNotFoundException rather than returning an empty string.


Originally reported by dtrebbien, imported from: hudson.Util.loadFile() has a race condition
  • status: Resolved
  • priority: Minor
  • component(s): core
  • label(s): 2.107.2-fixed
  • resolution: Fixed
  • resolved: 2018-03-11T18:12:43+00:00
  • votes: 0
  • watchers: 2
  • imported: 2025-11-24
Raw content of original issue

Util.loadFile() first checks if the file exists via File.exists(). It then tries to open the file for reading. However, it is possible for the file to be deleted between the existence check and the file-open operation, in which case the method throws a FileNotFoundException rather than returning an empty string.

Activity

  1. jenkins-infra-bot commented on Mar 7, 2018

    @jenkins-infra-bot
    Author
    dtrebbien:

    #3225

  2. jenkins-infra-bot commented on Mar 11, 2018

    @jenkins-infra-bot
    Author
    oleg_nenashev:
    • Original comment link
    • Raw content of original comment:

      The patch has been integrated towards 2.111

    The patch has been integrated towards 2.111

  3. jenkins-infra-bot commented on Mar 25, 2018

    @jenkins-infra-bot
    Author
    scm_issue_link:
    • Original comment link
    • Raw content of original comment:

      Code changed in jenkins User: Daniel Trebbien Path: core/src/main/java/hudson/Util.java http://jenkins-ci.org/commit/jenkins/aa799e39ad904183d1da3105b8b3267c7348cd71 Log: JENKINS-49971 Fix a race condition in Util.loadFile() (#3225)

      • Fix a race condition in Util.loadFile()

      If the file is deleted in between when its existence is checked and the file is opened for reading, then the method will fail to return an empty string.

      • Switch to using FileUtils.readFileToString()

      (cherry picked from commit aaae71af4bd2952efdc3462fde086faa6a604ee2)

      Compare: 115612b...aa799e3

    Code changed in jenkins
    User: Daniel Trebbien
    Path:
    core/src/main/java/hudson/Util.java
    http://jenkins-ci.org/commit/jenkins/aa799e39ad904183d1da3105b8b3267c7348cd71
    Log:
    JENKINS-49971 Fix a race condition in Util.loadFile() (#3225)

    • Fix a race condition in Util.loadFile()

    If the file is deleted in between when its existence is checked and the
    file is opened for reading, then the method will fail to return an empty
    string.

    • Switch to using FileUtils.readFileToString()

    (cherry picked from commit aaae71a)

    Compare: 115612b...aa799e3

  4. removed
    bugFor changelog: Minor bug. Will be listed after features
    on Nov 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions