JDK-8354450 : A File should be invalid if an element of its name sequence ends with a space
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 25
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows
  • Submitted: 2025-04-11
  • Updated: 2025-06-11
  • Resolved: 2025-06-03
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 25
25 b26Fixed
Related Reports
Duplicate :  
Sub Tasks
JDK-8358214 :  
Description
The following code snippets should fail but do not:

1. Trailing space in a file name

File f = new File("Something ");
String s = f.getCanonicalPath();

2. Trailing space in a directory name

File f = new File("foo\\bar \\gus");
String s = f.getCanonicalPath();
Comments
Changeset: 57862005 Branch: master Author: Brian Burkhalter <bpb@openjdk.org> Date: 2025-06-03 16:32:12 +0000 URL: https://git.openjdk.org/jdk/commit/57862005f9914ce60aa389a6e35d2e0cd38f8c35
03-06-2025

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/24635 Date: 2025-04-14 20:57:17 +0000
14-04-2025

In java.io.WinNTFileSystem.isInvalid(), this check // Valid if there is no ":" present or if the last ":" present is // at index 1 and the first character is a latter if (lastColon < 0 || (lastColon == 1 && isLetter(pathname.charAt(0)))) return false; occurs before NIO would be used to validate the path. If the path is determined valid by this check but contains a trailing space, then the returned value will be incorrect. The above should be changed to check for the opposite condition, which would indicate an invalid path, and return true if that is the case.
11-04-2025