JDK-8374342 : Remove incorrect @throws NoSuchFileException from FileUtils.java
  • Type: Bug
  • Component: core-libs
  • Affected Version: 17,21,25
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: generic
  • CPU: generic
  • Submitted: 2025-12-24
  • Updated: 2025-12-25
Description
ADDITIONAL SYSTEM INFORMATION :
Generic / MacOS / Java 21

A DESCRIPTION OF THE PROBLEM :
FileUtils.java `deleteFileIfExistsWithRetry` method documentation states "No exception thrown if file doesn't exist", while the @throws clause lists NoSuchFileException.

The `deleteFileIfExistsWithRetry` method at lines 98-110 has documentation stating "No exception thrown if file doesn't exist" in the first sentence. The `@throws` clause at line 104 declares `NoSuchFileException` may be thrown. The implementation checks `Files.notExists(path)` before calling `deleteFileWithRetry0(path)`. If `Files.notExists(path)` returns true, `deleteFileWithRetry0` is not called and no exception is thrown. The documentation contradicts itself between the first sentence and the `@throws` clause.

REGRESSION : Last worked in version 21.0.9-oracle

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
N/A - Documentation analysis only.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The documentation is expected to consistently state whether `NoSuchFileException` can be thrown when the file does not exist.

ACTUAL -
The first sentence states no exception is thrown, while the `@throws` clause lists `NoSuchFileException` as a possible exception.



Comments
A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/28985 Date: 2025-12-25 01:06:33 +0000
25-12-2025