Skip to content
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

8303260: (fc) FileChannel::transferFrom should support position > size() #12797

Closed
wants to merge 6 commits into from

Conversation

bplb
Copy link
Member

@bplb bplb commented Mar 1, 2023

Enhance FileChannel::transferFrom to extend the channel's file if position > size(). This is consistent with FileChannel::write(ByteBuffer, long).


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change requires CSR request JDK-8303474 to be approved

Issues

  • JDK-8303260: (fc) FileChannel::transferFrom should support position > size()
  • JDK-8303474: (fc) FileChannel::transferFrom should support position > size() (CSR)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/12797/head:pull/12797
$ git checkout pull/12797

Update a local copy of the PR:
$ git checkout pull/12797
$ git pull https://git.openjdk.org/jdk.git pull/12797/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 12797

View PR using the GUI difftool:
$ git pr show -t 12797

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/12797.diff

Webrev

Link to Webrev Comment

@bplb
Copy link
Member Author

bplb commented Mar 1, 2023

/csr

@bridgekeeper
Copy link

bridgekeeper bot commented Mar 1, 2023

👋 Welcome back bpb! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added rfr Pull request is ready for review csr Pull request needs approved CSR before integration labels Mar 1, 2023
@openjdk
Copy link

openjdk bot commented Mar 1, 2023

@bplb has indicated that a compatibility and specification (CSR) request is needed for this pull request.

@bplb please create a CSR request for issue JDK-8303260 with the correct fix version. This pull request cannot be integrated until the CSR request is approved.

@openjdk
Copy link

openjdk bot commented Mar 1, 2023

@bplb The following label will be automatically applied to this pull request:

  • nio

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the nio nio-dev@openjdk.org label Mar 1, 2023
@mlbridge
Copy link

mlbridge bot commented Mar 1, 2023

Webrevs

Copy link
Contributor

@AlanBateman AlanBateman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The update to the API docs looks okay, the implementation change looks fine. I'm just wondering if there is anything that we might be missing to explain the restriction in the original API.

@openjdk openjdk bot removed the csr Pull request needs approved CSR before integration label Mar 2, 2023
@bplb bplb requested a review from AlanBateman March 3, 2023 16:23
@altrisi
Copy link
Contributor

altrisi commented Mar 5, 2023

Unrelated to the content of this PR, but the bot seems to be obsessed with editing the main comment description, at the time of writing it has made 4852 edits, seems to make around one per minute. Thought I'd mention it given it's easy to miss so I figured this way it's more likely to get resolved.

@jaikiran
Copy link
Member

jaikiran commented Mar 8, 2023

Unrelated to the content of this PR, but the bot seems to be obsessed with editing the main comment description, at the time of writing it has made 4852 edits, seems to make around one per minute.

Noted. Thank you @altrisi. The team that deals with skara bots has been made aware of this issue https://bugs.openjdk.org/browse/SKARA-1837

@AlanBateman
Copy link
Contributor

The spec + impl changes looks fine.

Is this test copied/edited from an older test? Configuration name FAST_TRANSFER_xxx looks a bit odd and maybe we just replace it with a simpler JUnit style test?

@mlbridge
Copy link

mlbridge bot commented Mar 11, 2023

Mailing list message from Brian Burkhalter on nio-dev:

On Mar 10, 2023, at 2:43 AM, Alan Bateman <alanb at openjdk.org<mailto:alanb at openjdk.org>> wrote:

On Wed, 1 Mar 2023 01:34:33 GMT, Brian Burkhalter <bpb at openjdk.org<mailto:bpb at openjdk.org>> wrote:

Enhance `FileChannel::transferFrom` to extend the channel's file if `position > size()`. This is consistent with `FileChannel::write(ByteBuffer, long)`.

The spec + impl changes looks fine.

Is this test copied/edited from an older test?

No, I don?t recall doing that.

Configuration name FAST_TRANSFER_xxx looks a bit odd and maybe we just replace it with a simpler JUnit style test?

Will investigate.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/nio-dev/attachments/20230310/1be57c51/attachment.htm>

@bplb
Copy link
Member Author

bplb commented Mar 15, 2023

[M]aybe we just replace it (the test) with a simpler JUnit style test?

Addressed by 0639c23.


/* @test
* @bug 8303260
* @summary Test transferFrom to a position greater than size
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be clearer to say "file size" as it might be read as the transfer size.

// sun.nio.ch.FileChannelImpl::MAPPED_TRANSFER_THRESHOLD (16K).
// This method therefore tests the direct path on Linux and the mapped
// path on other platforms.
//
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be possible to change the method description to /* .. */. Also I wonder if we can trim down this comment as it will go stale very quickly due to churn in the implementation. Maybe reduce it down to say that it tests transfer from a channel type that may be optimized?

*/
private static void transferFrom(ReadableByteChannel src, long count,
long initialPos, long offset, byte[] bytes)
throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you fix the indention here, it's hard to see where the method declaration ends and the body starts.

* position is greater than or equal to the file's current size then the
* file will be grown to accommodate the new bytes; the values of any bytes
* between the previous end-of-file and the newly-written bytes are
* unspecified. </p>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing that I missed in the initial round is that the description of parameter "position" says "within the file". That is no longer correct, it should say "The file position at which the transfer is to begin".

long position = target.size() + offset;
long transferred = target.transferFrom(src, position, count);
assertTrue(transferred >= 0, "transferFrom returned negative");
assertFalse(transferred > count, transferred + " > " + count);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a bit clearer to assert that transferred < count.

@ParameterizedTest
@MethodSource("readingByteChannelParamProvider")
void fromReadingByteChannel(long initialPosition, int bufSize, long offset)
throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent issue here too.

* @param offset the offset beyong the end of the target channel
* @param bytes the bytes expected to be transferred
*/
private static void transferFrom(ReadableByteChannel src, long count,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would you think about renaming this method to testTransferFrom as that makes it clearer at the use-sites.

//
@ParameterizedTest
@MethodSource("fastParamProvider")
void fromFast(long initialPosition, int bufSize, long offset) throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be clearer to rename this fromFileChannel.

@openjdk
Copy link

openjdk bot commented Apr 4, 2023

@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:

8303260: (fc) FileChannel::transferFrom should support position > size()

Reviewed-by: alanb

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 466 new commits pushed to the master branch:

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 master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Apr 4, 2023
@bplb
Copy link
Member Author

bplb commented Apr 4, 2023

/integrate

@openjdk
Copy link

openjdk bot commented Apr 4, 2023

Going to push as commit 7baccd9.
Since your change was applied there have been 476 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Apr 4, 2023
@openjdk openjdk bot closed this Apr 4, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Apr 4, 2023
@openjdk
Copy link

openjdk bot commented Apr 4, 2023

@bplb Pushed as commit 7baccd9.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@bplb bplb deleted the FileChannel-transferFrom-8303260 branch April 5, 2023 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrated Pull request has been integrated nio nio-dev@openjdk.org
4 participants