-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8263898: (fs) Files.newOutputStream on the "NUL" special device throws FileSystemException: "nul: Incorrect function" (win) #3183
Conversation
…s FileSystemException: "nul: Incorrect function" (win)
👋 Welcome back bpb! A progress list of the required criteria for merging this PR into |
Webrevs
|
} else if (size.QuadPart != 0) { | ||
throwWindowsException(env, error); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The native methods are meant to map to one win32 call where possible. In this case, I think the workaround needs to be in WindowsChannelFile.open.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know. I tried at the Java level first and one cannot verify the size of the NUL device from Java.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's okay to add a new method to WindowsNativeDispatcher if we need it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added GetFileSizeEx()
.
* @summary Verify a byte can be written to the null device. | ||
* @run main NullDevice | ||
*/ | ||
public class NullDevice { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello Brian,
Given what's being tested here, perhaps this test should only be run against Windows OS? So maybe something like @requires os.family=="windows"
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are correct, I intended to but forgot to add that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added suggested @requires
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test case (changes) looks fine to me. Thank you Brian.
System.out.printf("Wrote a byte to %s%n", f); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The updated changes to the Windows file system provider looks good. Have you checked that WindowsNativeDispatcher.GetFileSizeEx returns the correct size for a non-zero length file? (asking about that because it won't be exercised by the any of the tests and we might want to use it in order places).
The test name is "NullDevice" but it actually tests "nul" :-) so maybe it should be renamed. Files.newOutputStream is just one way to open the NUL device for writing. Would be good to also test opening it for wring without the TRUNCATE_EXISTING operation. I think we should do reading while we are there.
You can use Path.of("nul") to avoid first creating a java.io.File and using toPath.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have the length check in public code. I'll see how it is possible. I'll translate "null" into French and look at the reading and writing cases. I should have thought to use Path.of()
especially given that I wrote it (JDK-8194746).
Thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change looks okay.
The test looks okay although there other cases that probably should be added at some point, in particular, FileChannel.open for reading, and AsynchronousFileChannel read & write.
*/ | ||
public class NulDevice { | ||
public static void main(final String[] args) throws IOException { | ||
System.getProperties().list(System.out); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the printing of the system properties a left-over?
@bplb This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 183 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
try (final OutputStream os = Files.newOutputStream(path)) { | ||
os.write(0x02); | ||
System.out.printf("Wrote a byte to %s%n", path); | ||
try (InputStream is = Files.newInputStream(path);) { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
Mailing list message from Brian Burkhalter on nio-dev: On Mar 27, 2021, at 8:57 AM, Alan Bateman <alanb at openjdk.java.net<mailto:alanb at openjdk.java.net>> wrote: 8263898: Fix accidentally reverted copyright year The change looks okay. The test looks okay although there other cases that probably should be added at some point, in particular, FileChannel.open for reading, and AsynchronousFileChannel read & write. Added. test/jdk/java/nio/file/Files/NulDevice.java line 41: 39: public class NulDevice { Is the printing of the system properties a left-over? Yes, it is vestigial; removed. On Mar 28, 2021, at 8:24 AM, Alan Bateman <alanb at openjdk.java.net<mailto:alanb at openjdk.java.net>> wrote: test/jdk/java/nio/file/Files/NulDevice.java line 47: 45: os.write(0x02); One other test that you could add here is to test that available() returns 0. I've no doubt there are many file operations that will behavior in surprising ways when using the special "NUL" device if the common operations work in unsurprising ways then it would help. Added. |
} | ||
|
||
try (final FileChannel ch = FileChannel.open(path, CREATE, | ||
TRUNCATE_EXISTING, WRITE)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean to put a line break here? Same at L87. Asking because it would be easier to read if the open options were on the same line. If line length is the concern then you could drop the spurious "final" modifier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
/integrate |
@bplb Since your change was applied there have been 185 commits pushed to the
Your commit was automatically rebased without conflicts. Pushed as commit 353807c. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
This request proposes to change the native method
WindowsNativeDispatcher.SetEndOfFile()
to succeed even if the Windows functionSetEndOfFile()
returns zero ifGetFileSizeEx()
called on the handle succeeds and reveals a file size of zero.Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/3183/head:pull/3183
$ git checkout pull/3183
Update a local copy of the PR:
$ git checkout pull/3183
$ git pull https://git.openjdk.java.net/jdk pull/3183/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 3183
View PR using the GUI difftool:
$ git pr show -t 3183
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/3183.diff