Compilation fails on Windows when a sibling file name contains illegal char":"
Eirik Bjørsnøs
eirbjo at gmail.com
Wed Aug 21 13:35:55 UTC 2024
Consider the following scenario where a valid Java source file is compiled
in a directory containing a sibling file with a colon in its file name:
Z:\>dir /B
file:txt
HelloWorld.java
Compilation fails as follows:
Z:\>javac HelloWorld.java
HelloWorld.java:1: error: cannot access unnamed package
public class HelloWorld {
^
error accessing directory
Z:\invalid-pathjava.nio.file.InvalidPathException: Illegal char <:> at
index 4: file:txt
1 error
printing javac parameters to: Z:\invalid-path\javac.20240821_151610.args
The "error accessing directory" message seems to have been introduced in
JDK-8177332.
The root exception seems to be thrown in WindowsPathParser.normalize.
Questions:
o Is this kind of failure expected according to the JLS and/or common sense?
o If yes, would it be worthwhile to improve the error reporting? "Cannot
access unnamed package" is not super helpful, "error accessing directory"
is also somewhat vague.
o At the very least, should we add a space in the IOException message
thrown by DirectoryContainer.list, to separate the file path from
the InvalidPathException toString?
Cheers,
Eirik.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/compiler-dev/attachments/20240821/523d75e7/attachment-0001.htm>
More information about the compiler-dev
mailing list