8024695: new File("").exists() returns false whereas it is the current working directory

Reviewed-by: alanb, rriggs, lancea
This commit is contained in:
Brian Burkhalter 2025-02-26 16:24:25 +00:00
parent 3e46480dcf
commit 9477c705c0
5 changed files with 308 additions and 47 deletions

View file

@ -56,7 +56,8 @@ import jdk.internal.util.StaticProperty;
* case of Microsoft Windows UNC pathnames, a hostname. Each subsequent name
* in an abstract pathname denotes a directory; the last name may denote
* either a directory or a file. The <em>empty</em> abstract pathname has no
* prefix and an empty name sequence.
* prefix and an empty name sequence. Accessing a file with the empty abstract
* pathname is equivalent to accessing the current user directory.
*
* <p> The conversion of a pathname string to or from an abstract pathname is
* inherently system-dependent. When an abstract pathname is converted into a

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -33,6 +33,22 @@ import java.lang.annotation.Native;
abstract class FileSystem {
/* -- Current Working Directory --*/
/* lazy initialization of CWD object */
private static class CurrentWorkingDirectoryHolder {
static final File CURRENT_WORKING_DIRECTORY = currentWorkingDirectory();
private static final File currentWorkingDirectory() {
return new File(".");
}
}
/* CWD object accessor */
static File getCWD() {
return CurrentWorkingDirectoryHolder.CURRENT_WORKING_DIRECTORY;
}
/* -- Normalization and construction -- */
/**