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

JDK-8297605 DelayQueue javadoc is confusing #12729

Closed
wants to merge 1 commit into from

Conversation

viktorklang-ora
Copy link
Contributor

@viktorklang-ora viktorklang-ora commented Feb 23, 2023

Clarifies the distinction between expiration of the head of DelayQueue and how it relates to poll, take, and peek. See discussion on https://bugs.openjdk.org/browse/JDK-8297605

@DougLea If possible, please weigh in on whether this is in line with your thoughts on the matter.


Progress

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

Integration blocker

 ⚠️ Title mismatch between PR and JBS for issue JDK-8297605

Issues

  • JDK-8297605: improve DelayQueue removal method javadoc ⚠️ Title mismatch between PR and JBS. ⚠️ Issue is already resolved. Consider making this a "backport pull request" by setting the PR title to Backport <hash> with the hash of the original commit. See Backports.
  • JDK-8304686: improve DelayQueue removal method javadoc (CSR)

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 12729

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

Using diff file

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

@viktorklang-ora
Copy link
Contributor Author

Updated version of #12727

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 23, 2023

👋 Welcome back viktorklang-ora! 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 the rfr Pull request is ready for review label Feb 23, 2023
@openjdk
Copy link

openjdk bot commented Feb 23, 2023

@viktorklang-ora The following label will be automatically applied to this pull request:

  • core-libs

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 core-libs core-libs-dev@openjdk.org label Feb 23, 2023
@mlbridge
Copy link

mlbridge bot commented Feb 23, 2023

Webrevs

@DougLea
Copy link
Contributor

DougLea commented Feb 23, 2023

Thanks. Adding the word "expired" (plus other adjustments) seems to be the simplest way to avoid confusion.

@@ -51,8 +51,7 @@
* {@code Delayed} elements, in which an element can only be taken
* when its delay has expired. The <em>head</em> of the queue is that
* {@code Delayed} element whose delay expired furthest in the
* past. If no delay has expired there is no head and {@code poll}
Copy link
Member

Choose a reason for hiding this comment

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

I like introducing the concept of "expired head".
Aren't we defining "expired head" here, not "head"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Martin-Buchholz I read the line before the removed line (The head of the queue is that {@code Delayed} element whose delay expired furthest in the past.) as defining that the head will be the thing with the "soonest" expiry, which is important if one is used to LIFO or FIFO. Any idea on how we could improve that sentence? 🤔

Copy link
Member

@Martin-Buchholz Martin-Buchholz left a comment

Choose a reason for hiding this comment

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

I like extending this approach as follows:

  • define "head"
  • define "expired head"
  • make it clear that some methods operate on all elements (regardless of their expiration status), some only on expired elements.
  • ensure that all public methods have an overriding javadoc that makes the distinction clear. e.g. currently remove() needs such an overriding javadoc.
    (writing good spec is hard work!)

@Martin-Buchholz
Copy link
Member

Martin-Buchholz commented Feb 23, 2023

Here's my attempt:

 * An unbounded {@linkplain BlockingQueue blocking queue} of {@link Delayed}
 * elements, in which an element generally becomes eligible for removal when its
 * delay has expired.
 *
 * <p>An element is considered <em>expired</em> when its {@code
 * getDelay(TimeUnit.NANOSECONDS)} method would return a value less than or
 * equal to zero.
 *
 * <p>An element is considered the <em>head</em> of the queue if it is the
 * element with the earliest expiration time, whether in the past or the future,
 * if there is such an element.
 *
 * <p>An element is considered the <em>expired head</em> of the queue if it is
 * the <em>expired</em> element with the earliest expiration time in the
 * past, if there is such an element.
 * The <em>expired head</em>, when present, is also the <em>head</em>.
 *
 * <p>While this class implements the {@code BlockingQueue} interface, it
 * intentionally violates the general contract of {@code BlockingQueue}, in that
 * the following methods disregard the presence of unexpired elements and only
 * ever remove the <em>expired head</em>:
 *
 * <ul>
 * <li> {@link #poll()}
 * <li> {@link #poll(long,TimeUnit)}
 * <li> {@link #take()}
 * <li> {@link #remove()}
 * </ul>
 *
 * <p>All other methods operate on both expired and unexpired elements.  For
 * example, the {@code size} method returns the count of all elements.  Method
 * {@link peek()} may return the non-null <em>head</em> even when {@code
 * take()} would block waiting for that element to expire.
 *
 * <p>This queue does not permit null elements.

@openjdk
Copy link

openjdk bot commented Feb 24, 2023

@viktorklang-ora Please do not rebase or force-push to an active PR as it invalidates existing review comments. Note for future reference, the bots always squash all changes into a single commit automatically as part of the integration. See OpenJDK Developers’ Guide for more information.

@viktorklang-ora
Copy link
Contributor Author

Here's my attempt:

 * An unbounded {@linkplain BlockingQueue blocking queue} of {@link Delayed}
 * elements, in which an element generally becomes eligible for removal when its
 * delay has expired.
 *
 * <p>An element is considered <em>expired</em> when its {@code
 * getDelay(TimeUnit.NANOSECONDS)} method would return a value less than or
 * equal to zero.
 *
 * <p>An element is considered the <em>head</em> of the queue if it is the
 * element with the earliest expiration time, whether in the past or the future,
 * if there is such an element.
 *
 * <p>An element is considered the <em>expired head</em> of the queue if it is
 * the <em>expired</em> element with the earliest expiration time in the
 * past, if there is such an element.
 * The <em>expired head</em>, when present, is also the <em>head</em>.
 *
 * <p>While this class implements the {@code BlockingQueue} interface, it
 * intentionally violates the general contract of {@code BlockingQueue}, in that
 * the following methods disregard the presence of unexpired elements and only
 * ever remove the <em>expired head</em>:
 *
 * <ul>
 * <li> {@link #poll()}
 * <li> {@link #poll(long,TimeUnit)}
 * <li> {@link #take()}
 * <li> {@link #remove()}
 * </ul>
 *
 * <p>All other methods operate on both expired and unexpired elements.  For
 * example, the {@code size} method returns the count of all elements.  Method
 * {@link peek()} may return the non-null <em>head</em> even when {@code
 * take()} would block waiting for that element to expire.
 *
 * <p>This queue does not permit null elements.

I think that approach sounds good. @DougLea, any opinion on this class javadoc summary?

@DougLea
Copy link
Contributor

DougLea commented Feb 27, 2023

Yes, lgtm!

@viktorklang-ora
Copy link
Contributor Author

@Martin-Buchholz Martin, how would you like to proceed with your proposed wording, would you prefer a suggested edit to this PR, do a separate PR, or otherwise? /cc @AlanBateman (any recommendation, Alan? 🤔 )

@Martin-Buchholz
Copy link
Member

@Martin-Buchholz Martin, how would you like to proceed with your proposed wording, would you prefer a suggested edit to this PR, do a separate PR, or otherwise? /cc @AlanBateman (any recommendation, Alan? thinking )

Talked me into it - I will dust off my github/skara skillz and make a new PR.

I wonder if there's now a way to override javadoc for remove() without creating a new method body.

@viktorklang-ora
Copy link
Contributor Author

@Martin-Buchholz I guess remove could be overridden and just delegate to super?

@Martin-Buchholz
Copy link
Member

I wonder if there's now a way to override javadoc for remove() without creating a new method body.

I thought recent javadoc features might have been useful here, but I scanned the results from this jql:

subcomponent in ( "javadoc(tool)", "doclet" )  AND (resolution in ( Fixed, Approved ) ) AND issuetype in (JEP, Enhancement) ORDER BY resolved  DESC

and came up empty

@viktorklang-ora
Copy link
Contributor Author

Perhaps @pavelrappo has any suggestion for adding clarifying Javadoc to a subclass without having to override the method? 🤔

@pavelrappo
Copy link
Member

Perhaps @pavelrappo has any suggestion for adding clarifying Javadoc to a subclass without having to override the method? 🤔

You cannot do that.

@viktorklang-ora
Copy link
Contributor Author

@Martin-Buchholz @pavelrappo OTOH I see that DelayQueue has already overridden remove(Object o) so you should be able to modify that?

@Martin-Buchholz
Copy link
Member

@Martin-Buchholz @pavelrappo OTOH I see that DelayQueue has already overridden remove(Object o) so you should be able to modify that?

Right. But remove(Object) unlike remove() doesn't consider the expiration time. Confusing!

@Martin-Buchholz
Copy link
Member

Right. But remove(Object) unlike remove() doesn't consider the expiration time. Confusing!

Actually, confusion extends to three methods with the same name:

  • Queue.remove()
  • Collection.remove(Object)
  • Iterator.remove()

@viktorklang-ora
Copy link
Contributor Author

@Martin-Buchholz Oh that remove() :)

@openjdk openjdk bot added the csr Pull request needs approved CSR before integration label Mar 21, 2023
@openjdk openjdk bot removed the csr Pull request needs approved CSR before integration label Mar 31, 2023
@openjdk
Copy link

openjdk bot commented Mar 31, 2023

@viktorklang-ora this pull request can not be integrated into master due to one or more merge conflicts. To resolve these merge conflicts and update this pull request you can run the following commands in the local repository for your personal fork:

git checkout 8297605
git fetch https://git.openjdk.org/jdk.git master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push

@openjdk openjdk bot added merge-conflict Pull request has merge conflict with target branch and removed rfr Pull request is ready for review labels Mar 31, 2023
@viktorklang-ora
Copy link
Contributor Author

Superseded by #12838

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org merge-conflict Pull request has merge conflict with target branch
4 participants