-
Notifications
You must be signed in to change notification settings - Fork 6.2k
JDK-8275308: Add valueOf(Runtime.Version) factory to SourceVersion #5973
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
Conversation
|
👋 Welcome back darcy! A progress list of the required criteria for merging this PR into |
Webrevs
|
| * {@code 17}, to the corresponding source version, {@code | ||
| * RELEASE_17}, is<br>: | ||
| * | ||
| * {@code SourceVersion.valueOf(Runtime.Version.parse(Integer.toString(17))) |
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.
| * {@code SourceVersion.valueOf(Runtime.Version.parse(Integer.toString(17))) | |
| * {@code SourceVersion.valueOf(Runtime.Version.parse(Integer.toString(17)))} |
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 understand that this PR is an invitation to a discussion, not the final solution. Still, it's easier to reason about API whose doc comments render properly.
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.
Doh! Sorry, fixed.
| * @apiNote | ||
| * An expression to convert from an integer value, for example | ||
| * {@code 17}, to the corresponding source version, {@code | ||
| * RELEASE_17}, is<br>: | ||
| * | ||
| * {@code SourceVersion.valueOf(Runtime.Version.parse(Integer.toString(17)))} |
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.
IMO, The use of integer value in the example is something of a distraction, and suggests a hole in the Runtime.Version API. IMO, a more likely use case is for code to have a string representing a version, perhaps found as an argument on the command line
|
although the new factory method is quite useful to convert from one version representation to another. Unfortunately, I don't think it would solve one particular use case (although a very niche one). NetBeans for example relies on javac for all its editor features and can optionally use a newer javac than the JDK has, on which it is running on. This allows to have java 17 editor features while starting NB on JDK 8 (for whatever reason). That is why you can find code like in apache/netbeans@56cf1c5 all over the place since it has to check a feature version against an enum which might not be there. And that is why my first thought went to "wouldn't it be nice if we could just compare ordinals or ask SourceVersion for the feature version int". Calling Calling But this is so niche that it is probably not worth considering. NB could just put somewhere which will work until the unlikely event of the enum having non-feature versions before it needs to be changed. (or just keep doing the static initializer workaround) |
|
Would it help to have a method that provides the inverse mapping |
|
@jonathan-gibbons I think that would help indeed. The conversion method would always be able to return a runtime version without throwing exceptions, which would make it a convenient way to access the feature version int. It seems to be also forward compatible to all (prob. unlikely) scenarios of SourceVersion adding non-feature-version enums. |
|
FWIW there is one place in javadoc that would also benefit from a SourceVersion to Runtime.Version conversion method. (That code would be less ugly if it used jdk/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Extern.java Lines 336 to 342 in ebb1363
|
|
In the latest push, stubbed in support for the reverse mapping from SourceVersion to a runtime version. For now, limiting the mapping to RELEASE_9 and higher since Runtime.Version was added in 9. |
| if (feature > Runtime.version().feature()) { | ||
| throw new IllegalArgumentException("No matching SourceVersion for " + rv); | ||
| } else { |
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.
Using Runtime.version() as a stand-in for the max SourceVersion seems non-obvious. Would it be better to use SourceVersion.latest().runtimeVersion() instead?
What about when running this API on JDK N-1?
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.
if could be potentially dropped since valueOf("RELEASE_" + feature) is throwing IAE already.
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.
Updated as suggested.
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.
Using
Runtime.version()as a stand-in for the maxSourceVersionseems non-obvious. Would it be better to useSourceVersion.latest().runtimeVersion()instead?What about when running this API on JDK N-1?
Updated the supported range to go up to the feature corresponding to SourceVersion.latest().
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 think this affects the doc comment and CSR.
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.
Right; I think the the current spec
* ... If the runtime version's {@linkplain
* Runtime.Version#feature() feature} is greater than the feature
* of the {@linkplain #runtimeVersion() runtime version} of the
* {@linkplain #latest() latest source version}, an {@code
* IllegalArgumentException} is thrown.
does reflect that.
Thanks for adding the reverse mapping! Is there a problem with Source.Version representing a version earlier than 9, other than that it was added in that release? Supporting earlier versions would be very useful for javadoc, where we support versions starting from 7. |
Added support back to 6, the release the javax.lang.model API was added. Strictly speaking release 6, 7, and 8 aren't modeled by Runtime.Version, but just using the feature value can be reasonable. I don't think it is worthwhile to formally map, for instance, RELEASE_5 to something like RuntimeVersion.parse("5.0") or RuntimeVersion.parse("5.0.0") to try to model the versioning scheme used then. |
Changed to RELEASE 6 and later in the latest push; the javax.lang.model API was added in JDK 6. |
|
would the doc need |
|
/csr needed |
|
CSR now available for review: https://bugs.openjdk.java.net/browse/JDK-8275888 |
|
@jddarcy this pull request will not be integrated until the CSR request JDK-8275888 for issue JDK-8275308 has been approved. |
Sure; added. |
|
Any more comments on this PR? |
| * {@return the latest source version that is usable under the | ||
| * runtime version argument} If the runtime version's {@linkplain | ||
| * Runtime.Version#feature() feature} is greater than the feature | ||
| * of the {@linkplain #runtimeVersion() runtime version} of the | ||
| * {@linkplain #latest() latest source version}, an {@code | ||
| * IllegalArgumentException} is thrown. |
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.
👍
|
@jddarcy 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 no new commits pushed to the ➡️ To integrate this PR with the above commit message to the |
|
/integrate |
|
Going to push as commit 48f3fca. |
I wanted to get input on the design of API of the method before writing the tests.
The new factory method maps from a Runtime.Version object, a object which formally modes the version of the JDK, to a corresponding SourceVersion object.
Given the current histories of versioning of the JDK and SourceVersion this amount to mapping "JDK N" to RELEASE_N, for example, JDK 17 to RELEASE_17, etc. As mentioned in the API note, this could potentially change in the future if the release model changes. Runtime.Version has added in JDK 9, but earlier versions can be modeled. Note that no attempt is made to map "1.2" to RELEASE_2 and that since Runtime.Version grammar does not allow a leading 0 term, RELEASE_0 will not be returned by the new method.
Another design point: an out-of-range feature version is treated as an error so a Runtime.Version with a feature of 19 mapped in JDK 18 will fail with an IllegalArgumentException rather than saturating at RELEASE_18. If saturating would be more helpful for the envisioned use cases, I'm open to changing the spec accordingly.
CSR to follow once the API is nailed down.
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/5973/head:pull/5973$ git checkout pull/5973Update a local copy of the PR:
$ git checkout pull/5973$ git pull https://git.openjdk.java.net/jdk pull/5973/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 5973View PR using the GUI difftool:
$ git pr show -t 5973Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/5973.diff