-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
8316971: Add Lint warning for restricted method calls #15964
Conversation
@@ -23,7 +23,7 @@ | |||
# questions. | |||
# | |||
|
|||
DISABLED_WARNINGS_java += this-escape | |||
DISABLED_WARNINGS_java += this-escape restricted |
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've disabled restricted warnings in java.base as there's a lot of restricted calls in the Linker API implementation :-)
👋 Welcome back mcimadamore! A progress list of the required criteria for merging this PR into |
@@ -91,7 +91,7 @@ $(eval $(call SetupJavaCompilation, BUILD_JDK_MICROBENCHMARK, \ | |||
TARGET_RELEASE := $(TARGET_RELEASE_NEWJDK_UPGRADED), \ | |||
SMALL_JAVA := false, \ | |||
CLASSPATH := $(MICROBENCHMARK_CLASSPATH), \ | |||
DISABLED_WARNINGS := this-escape processing rawtypes cast serial preview, \ | |||
DISABLED_WARNINGS := restricted this-escape processing rawtypes cast serial preview, \ |
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.
This is needed so that we can compile FFM API benchmarks.
@mcimadamore The following labels will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command. |
@@ -215,3 +215,6 @@ compiler.misc.illegal.signature # the compiler can | |||
|
|||
# this one needs a forged class file to be reproduced | |||
compiler.err.annotation.unrecognized.attribute.name | |||
|
|||
# this one is transitional (waiting for FFM API to exit preview) |
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.
Note: in principle I could have added an example for this diagnostic. In practice, the fact that FFM is still a preview API makes this a bit difficult - because we need the sample to also have enable preview flags, and also to catch a bunch of preview diagnostics (some of which I can't add directly as they are also excluded on this file). Since this PR already adds a test, I opted to exclude the diagnostic sample for now, and I will come back later (after FFM is no longer preview) to add one (so as to minimize disruption).
Webrevs
|
* @test /nodynamiccopyright/ | ||
* @bug 8316971 | ||
* @summary Smoke test for restricted method call warnings | ||
* @compile/fail/ref=RestrictedMethods.out -Xlint:restricted -Werror -XDrawDiagnostics --enable-preview --source ${jdk.version} RestrictedMethods.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.
The --enable-preview
related options will need to be removed when FFM is finalized
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.
Build changes look trivially fine.
/reviewers 2
@@ -389,6 +389,11 @@ public static EnumSet<Flag> asFlagSet(long flags) { | |||
*/ | |||
public static final long SEALED = 1L<<62; // ClassSymbols | |||
|
|||
/** | |||
* Flag to indicate sealed class/interface declaration. |
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.
this javadoc needs to be adjusted to restricted methods
question shouldn't the new Restricted annotation be annotated with the @PreviewFeature annotation? it depends on a preview feature |
MemorySegment.NULL.reinterpret(10); // no warning here | ||
} | ||
} | ||
} |
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.
shouldn't this test include a case using method references? For example:
void m(MemorySegment m) {
foo(m::reinterpret);
}
<R> void foo(LongFunction<R> f) {}
we could also clarify in the CSR that the warning will also be issued for method references where the identifier after ::
is a restricted method
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.
Good point. Will do.
The Restricted annotation is an internal annotation only. So there is no value in annotating it with |
@@ -1917,6 +1917,11 @@ compiler.err.is.preview=\ | |||
compiler.warn.is.preview.reflective=\ | |||
{0} is a reflective preview API and may be removed in a future release. | |||
|
|||
# 0: symbol, 1: symbol | |||
compiler.warn.restricted.method=\ |
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've updated the name of this key (from compiler.warn.restricted.method.call
to make it more general, and also applicable in the case of method reference. Note that the warning text itself has not changed, as that was already correct.
I see, 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.
looks good, thanks!
@mcimadamore 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 62 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 |
/integrate |
Going to push as commit 0d4de8a.
Your commit was automatically rebased without conflicts. |
@mcimadamore Pushed as commit 0d4de8a. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
This patch adds a new lint warning category, namely
-Xlint:restricted
to enable warnings on restricted method calls.The patch is relatively straightforward: javac marks methods that are marked with the
@Restricted
annotation with a corresponding internal flag. This is done both inAnnotate
when compiling JDK from source, and inClassReader
when JDK classfiles are read. When calls to methods marked with the special flag are found, a new warning is issued.While there are some similarities between this new warning and the preview API warnings, the compiler does not emit a mandatory note when a compilation unit is found to have one or more restricted method calls. In other words, this is just a plain lint warning.
The output from javac looks as follows:
Progress
Issues
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/15964/head:pull/15964
$ git checkout pull/15964
Update a local copy of the PR:
$ git checkout pull/15964
$ git pull https://git.openjdk.org/jdk.git pull/15964/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 15964
View PR using the GUI difftool:
$ git pr show -t 15964
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/15964.diff
Webrev
Link to Webrev Comment