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-8325189: Enable this-escape javac warning in java.base #17692

Closed
wants to merge 3 commits into from

Conversation

jddarcy
Copy link
Member

@jddarcy jddarcy commented Feb 2, 2024

After the "this-escape" lint warning was added to javac (JDK-8015831), the base module was not updated to be able to compile with this warning enabled. This PR makes the necessary changes to allow the base module to build with the warning enabled.


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

Issue

  • JDK-8325189: Enable this-escape javac warning in java.base (Enhancement - P3)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 17692

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 2, 2024

👋 Welcome back darcy! 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 2, 2024
@openjdk
Copy link

openjdk bot commented Feb 2, 2024

@jddarcy The following labels will be automatically applied to this pull request:

  • build
  • core-libs
  • i18n
  • net
  • nio
  • security

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.

@openjdk openjdk bot added security security-dev@openjdk.org nio nio-dev@openjdk.org build build-dev@openjdk.org core-libs core-libs-dev@openjdk.org net net-dev@openjdk.org i18n i18n-dev@openjdk.org labels Feb 2, 2024
@jddarcy
Copy link
Member Author

jddarcy commented Feb 2, 2024

In its initial form, the changes are tested on Linux. Later on, I'll do cross-platform builds to make sure there aren't any, say, windows-specific changes that are needed as well.

I can file a follow-up umbrella bug with the original list of ~200 warnings so the constructors and initializers in question can be examined to see if they should be updated.

@mlbridge
Copy link

mlbridge bot commented Feb 2, 2024

Webrevs

@jddarcy
Copy link
Member Author

jddarcy commented Feb 3, 2024

In its initial form, the changes are tested on Linux. Later on, I'll do cross-platform builds to make sure there aren't any, say, windows-specific changes that are needed as well.

PS Builds pass on all platforms (linux, mac, and windows) on Oracle's internal build system.

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.

I skimmed through the use sites and don't see any issues. There is one bucket of escaping "this" that will go away once the support for running with the SM goes away.

@openjdk
Copy link

openjdk bot commented Feb 4, 2024

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

8325189: Enable this-escape javac warning in java.base

Reviewed-by: alanb, erikj, naoto, smarks, ihse, joehw, lancea, weijun

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 master branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential 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 Feb 4, 2024
@jddarcy
Copy link
Member Author

jddarcy commented Feb 5, 2024

In its initial form, the changes are tested on Linux. Later on, I'll do cross-platform builds to make sure there aren't any, say, windows-specific changes that are needed as well.

I can file a follow-up umbrella bug with the original list of ~200 warnings so the constructors and initializers in question can be examined to see if they should be updated.

Filed JDK-8325263 .

Copy link
Member

@stuart-marks stuart-marks left a comment

Choose a reason for hiding this comment

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

Changes in java.util and java.util.concurrent look fine.

There are a startling number of places where this is potentially leaked to a subclass. It would be interesting to analyze the pathologies and have a discussion of potential fixes. There may also be compatibility issues with potential fixes (nothing in this PR that I can see) because the behavior can change from the point of view of subclasses.

Copy link
Member

@magicus magicus left a comment

Choose a reason for hiding this comment

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

Build changes look fine, but there is really a lot of places where the warning is individually disabled. This indicates either that the warning is too broad, or that the code base is potentially very buggy; neither of which sounds very good. :(

Copy link
Member

@dfuch dfuch left a comment

Choose a reason for hiding this comment

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

I looked at the modifications in java.net / sun.net. Looks generally good though I have some comments.

@@ -319,6 +320,7 @@ private static Void checkPermission(SocketImpl impl) {
* @see java.net.SocketImpl
* @see SecurityManager#checkConnect
*/
@SuppressWarnings("this-escape")
Copy link
Member

@dfuch dfuch Feb 6, 2024

Choose a reason for hiding this comment

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

This is a weird one. I guess the issue here is that the escape happens in the chained constructor, and is propagated recursively up the constructor chain. Is the suppress warning here still needed after disabling this-escape warning at line 358?

Actually - these are all weird since the only place where the escape happens is in the private constructor at line 548 - and it doesn't even get flagged there (presumably because it's a private constructor?)

I guess that the rationale is that subclasses cannot override the private constructor (where the escape happen), but can override the public constructor that calls the private constructor where the escape happen. I can't help feeling that the warning would be better placed on the private constructor though. Seeing it here confused me a lot.

@@ -50,6 +50,7 @@ public MessageHeader () {
grow();
}

@SuppressWarnings("this-escape")
Copy link
Member

Choose a reason for hiding this comment

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

An alternative here could be to make the class final. AFAICS it's not subclassed anywhere. If you'd prefer not to do this here then maybe a followup issue could be logged?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd prefer if that kind of change were done as a subtask of

JDK-8325263: Address this-escape lint warnings java.base (umbrella)

Copy link
Member

Choose a reason for hiding this comment

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

Thanks Joe. I logged JDK-8325361: Make sun.net.www.MessageHeader final

@jddarcy
Copy link
Member Author

jddarcy commented Feb 6, 2024

Build changes look fine, but there is really a lot of places where the warning is individually disabled. This indicates either that the warning is too broad, or that the code base is potentially very buggy; neither of which sounds very good. :(

I deliberately choose to suppress the warning at each constructor location rather than at the class level so there are more SuppressWarnings annotations than strictly needed to get the build to be clean. However, I thought limiting the scope of the annotations was preferable for several reasons, including more precisely indicating where any code updates are needed.

This is a new warning run over old code, in some cases very old code. I don't find it surprising that there were several hundred instances of this warning in java.base given the amount of code there.

Copy link
Member

@JoeWang-Java JoeWang-Java left a comment

Choose a reason for hiding this comment

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

The two XML changes look good to me. There would be a lot of warnings in the java.xml module as well, if we had to do it in the future.

Copy link
Contributor

@wangweij wangweij left a comment

Choose a reason for hiding this comment

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

Security changes look fine. Although I don't know how to remove those annotations later. A lot of compatibility impact.

@jddarcy
Copy link
Member Author

jddarcy commented Feb 7, 2024

Thanks all for the reviews. Will integrate now after a sync with mainline and successful cross-platform build run.

@jddarcy
Copy link
Member Author

jddarcy commented Feb 7, 2024

/integrate

@openjdk
Copy link

openjdk bot commented Feb 7, 2024

Going to push as commit fbd15b2.

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

openjdk bot commented Feb 7, 2024

@jddarcy Pushed as commit fbd15b2.

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

@jddarcy
Copy link
Member Author

jddarcy commented Feb 7, 2024

Security changes look fine. Although I don't know how to remove those annotations later. A lot of compatibility impact.

In case you didn't see it, the warning message are listed in an attachment on JDK-8325263.

@jddarcy jddarcy deleted the JDK-8325189 branch October 17, 2024 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build build-dev@openjdk.org core-libs core-libs-dev@openjdk.org i18n i18n-dev@openjdk.org integrated Pull request has been integrated net net-dev@openjdk.org nio nio-dev@openjdk.org security security-dev@openjdk.org
Development

Successfully merging this pull request may close these issues.

10 participants