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

8252767: URLConnection.setRequestProperty throws IllegalAccessError #26

Closed
wants to merge 3 commits into from

Conversation

jaikiran
Copy link
Member

@jaikiran jaikiran commented Sep 6, 2020

Can I please get a review and a sponsor for a fix for the issue reported at https://bugs.openjdk.java.net/browse/JDK-8252767?

As noted in that issue, the sun.net.www.URLConnection#setRequestProperty is throwing a IllegalAccessError instead of a IllegalStateException. The commit here fixes that and includes a test which reproduces the issue and verifies the fix.

Would a CSR be needed for this change?


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8252767: URLConnection.setRequestProperty throws IllegalAccessError

Reviewers

Download

$ git fetch https://git.openjdk.java.net/jdk pull/26/head:pull/26
$ git checkout pull/26

@bridgekeeper bridgekeeper bot added the oca Needs verification of OCA signatory status label Sep 6, 2020
@bridgekeeper
Copy link

bridgekeeper bot commented Sep 6, 2020

Hi @jaikiran, welcome to this OpenJDK project and thanks for contributing!

We do not recognize you as Contributor and need to ensure you have signed the Oracle Contributor Agreement (OCA). If you have not signed the OCA, please follow the instructions. Please fill in your GitHub username in the "Username" field of the application. Once you have signed the OCA, please let us know by writing /signed in a comment in this pull request.

If you already are an OpenJDK Author, Committer or Reviewer, please click here to open a new issue so that we can record that fact. Please use "Add GitHub user jaikiran" as summary for the issue.

If you are contributing this work on behalf of your employer and your employer has signed the OCA, please let us know by writing /covered in a comment in this pull request.

@openjdk
Copy link

openjdk bot commented Sep 6, 2020

@jaikiran The following labels will be automatically applied to this pull request: net. 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 (add|remove) "label" command.

@openjdk openjdk bot added the net net-dev@openjdk.org label Sep 6, 2020
@jaikiran
Copy link
Member Author

jaikiran commented Sep 6, 2020

FYI - I am an "author" in the JDK project and have requested for linking this github account to my OpenJDK account (jpai) through this JBS issue https://bugs.openjdk.java.net/browse/SKARA-593

@bridgekeeper bridgekeeper bot removed the oca Needs verification of OCA signatory status label Sep 6, 2020
@jaikiran
Copy link
Member Author

jaikiran commented Sep 6, 2020

/solves 8252767

@openjdk openjdk bot changed the title RFR 8252767: URLConnection.setRequestProperty throws IllegalAccessError 8252767: URLConnection.setRequestProperty throws IllegalAccessError Sep 6, 2020
@openjdk
Copy link

openjdk bot commented Sep 6, 2020

@jaikiran The primary solved issue for a PR is set through the PR title. Since the current title does not contain an issue reference, it will now be updated.

@openjdk openjdk bot added the rfr Pull request is ready for review label Sep 6, 2020
@mlbridge
Copy link

mlbridge bot commented Sep 6, 2020

Webrevs

* when already connected
* @run testng URLConnectionTest
*/
public class URLConnectionTest {
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 better to put the test in test/jdk/java/net/URLConnection as its a test for URLConnection.setRequestProperty from the API user point of view. Also it's a a specific test for the behaviour of one method so I think needs a more specific name too ("URLConnectionTest" is too general)

Copy link
Member Author

Choose a reason for hiding this comment

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

Hello Alan,

There's a test/jdk/java/net/URLConnection/RequestProperties.java test class which tests the setRequestProperty for NullPointerException expectations of that API. Perhaps it would be OK to add this test into that class?

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've now updated this PR to move the test into test/jdk/java/net/URLConnection/RequestProperties.java

*/
private static void testSetRequestPropIllegalStateException() throws Exception {
final URL url = new URL("file://" + System.getProperty("java.io.tmpdir"));
final java.net.URLConnection conn = url.openConnection();
Copy link
Contributor

Choose a reason for hiding this comment

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

The URL creation isn't technically right as you can't reliably use a file path string as a URL path. Something like the following would be more correct:
URL url = Path.of(System.getProperty("java.io.tmpdir")).toUri().toURL();

Also minor nit but importing java.net.URL and not URLConnection is a bit strange.

Copy link
Member Author

Choose a reason for hiding this comment

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

The URL creation isn't technically right as you can't reliably use a file path string as a URL path. Something like the following would be more correct:
URL url = Path.of(System.getProperty("java.io.tmpdir")).toUri().toURL();

I've now updated the PR to fix this.

Also minor nit but importing java.net.URL and not URLConnection is a bit strange.

Sorry, that wasn't intentional. Not sure how I managed to do that. I've included this change in the updated PR.

Copy link
Member

@ChrisHegarty ChrisHegarty left a comment

Choose a reason for hiding this comment

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

Overall, this looks good. I added a few minor test related comments.

test/jdk/java/net/URLConnection/RequestProperties.java Outdated Show resolved Hide resolved
final URLConnection conn = url.openConnection();
conn.connect();
try {
conn.setRequestProperty("foo", "bar");
Copy link
Member

Choose a reason for hiding this comment

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

While here, and not directly related to this change, it would be good to add coverage for the other xxxRequestPropertXXX methods - to ensure that they also throw the correction exception when connected.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you for the review, Chris.

I've updated this PR to include these inputs into the test case.

Summary: Throw an IllegalStateException from sun.net.www.URLConnection#setRequestProperty when already connected
Reviewed-By:
Copy link
Member

@ChrisHegarty ChrisHegarty left a comment

Choose a reason for hiding this comment

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

LGTM.

@openjdk
Copy link

openjdk bot commented Sep 7, 2020

@jaikiran This change now passes all automated pre-integration checks. In addition to the automated checks, the change must also fulfill all project specific requirements

After integration, the commit message will be:

8252767: URLConnection.setRequestProperty throws IllegalAccessError

Reviewed-by: chegar, michaelm, alanb
  • If you would like to add a summary, use the /summary command.
  • To credit additional contributors, use the /contributor command.
  • To add additional solved issues, use the /issue command.

Since the source branch of this PR was last updated there have been 12 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 automatic rebasing, please merge master into your branch, and then specify the current head hash when integrating, like this: /integrate 2cceeedfe18f699bad4ec5718b0da3fe37364473.

As you do not have Committer status in this project, an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@ChrisHegarty, @Michael-Mc-Mahon, @AlanBateman) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Sep 7, 2020
@jaikiran
Copy link
Member Author

jaikiran commented Sep 7, 2020

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Sep 7, 2020
@openjdk
Copy link

openjdk bot commented Sep 7, 2020

@jaikiran
Your change (at version bd64977) is now ready to be sponsored by a Committer.

} catch (IllegalStateException ise) {
// expected
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that the test update is significant then it makes me wonder if we should just move to TestNG while we're at it. It would avoid needing to add expectIllegalStateException.
Minor inconsistency is that is the existing test now has "NPE" as the suffix, the new test "IllegalStateException" as the suffix. Also can we find a better name for "unmetExpectationErrorMessage" as it's not clear to maintainers what "unmet" means.

Copy link
Member Author

Choose a reason for hiding this comment

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

Given that the test update is significant then it makes me wonder if we should just move to TestNG while we're at it. It would avoid needing to add expectIllegalStateException.

I wasn't sure if it was OK to do it as part of this change. If that's fine, then I will go ahead and change this whole test class into TestNG based test.

@AlanBateman
Copy link
Contributor

I see Jaikiran has used "/integrate" but I don't think the review is complete yet. The change may be trivial but it's really important to give others a chance to comment if they wish.

@jaikiran
Copy link
Member Author

jaikiran commented Sep 7, 2020

I see Jaikiran has used "/integrate" but I don't think the review is complete yet. The change may be trivial but it's really important to give others a chance to comment if they wish.

Sorry, I'm new this whole flow. I saw the message from that bot asking me to issue that command. I then went into the "contributing" guidelines to see if there was anything else needed to be done but I didn't see anything specific, so went ahead and issued the /integrate.

I guess if I force push on to this PR, with that TestNG change that you recommended, perhaps the review process will put this PR into the original state which it was before the /integrate command?

@jaikiran
Copy link
Member Author

jaikiran commented Sep 7, 2020

Slightly OT - but I think this /integrate command shouldn't actually be in the hands of the contributor and instead should be decided and issued by "committers" or "sponsors". I don't really see how the contributor/author can realistically decide when it's the right time to intiate a /integrate

@ChrisHegarty
Copy link
Member

ChrisHegarty commented Sep 7, 2020

@jaikiran No need to be sorry, you are following the process as it is outlined. Please go ahead with the suggestion to update the test to use TestNG. The current state of the PR should not affect updates. BTW AFAIK, you should not need to "force push" - just push to the branch.

@rwestberg
Copy link
Member

@jaikiran For what it's worth, this is how the interaction was designed. When an author that isn't an OpenJDK Committer issues the /integrate command, it merely signals that you think the change is ready. If a reviewer disagrees, they will let you know, and you can continue to work on the pull request. Any new commit pushed to your branch will cause the "sponsor" label to be removed.

If the author didn't have to issue the /integrate command we would have the opposite problem - your sponsor can't know that you think that your contribution is really ready - perhaps you have another minor cleanup lined up and are just about to push it. But perhaps we can make this clearer in the message from the bot.

@openjdk openjdk bot removed the sponsor Pull request is ready to be sponsored label Sep 7, 2020
@jaikiran
Copy link
Member Author

jaikiran commented Sep 7, 2020

@jaikiran No need to be sorry, you are following the process as it is outlined. Please go ahead with the suggestion to update the test to use TestNG. The current state of the PR should not affect updates. BTW AFAIK, you should not need to "force push" - just push to the branch.

Thank you Chris. I've now updated this PR by doing a normal push. The updated PR now contains changes to the test, to convert it to TestNG.

Copy link
Member

@Michael-Mc-Mahon Michael-Mc-Mahon left a comment

Choose a reason for hiding this comment

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

LGTM

failed++;
} catch (NullPointerException e) { /* Expected */ }
conn.addRequestProperty(null, "hello");
Assert.fail("addRequestProperty on " + conn.getClass().getName()
Copy link
Member

Choose a reason for hiding this comment

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

Now that the test is using TestNG, you can use the convenient Assert.assertThrows / Assert.expectThrows, e.g. something like:

static final Class NPE = NullPointerException.class;

assertThrows(NPE, () -> conn.addRequestProperty(null, "hello"));

similar for IllegalStateException

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you. I wasn't aware of those APIs in TestNG. Looks like they got introduced in 6.9.5 of TestNG.
Not sure what version of TestNG, the jtreg tool supports. But when I changed this test to use those APIs and run it, it worked fine and passed. So I guess it's supported.
Using jtreg -version doesn't show the TestNG version (unlike what the docs claim), but that anyway isn't something relevant here and is a question to discuss on the jtreg mailing list:

jtreg -version
jtreg, version 5.1 dev 827
Installed in /home/me/jtreg/jtreg/lib/jtreg.jar
Running on platform version 1.8.0_265 from /home/me/java/Contents/Home/jre.
Built with Java(TM) 2 SDK, Version 1.8.0_172-b11 on June 21, 2020.
Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
Use is subject to license terms.
JT Harness, version 6.0 ea b11 (June 21, 2020)
JCov 3.0-2
TestNG (testng.jar): version unknown
TestNG (jcommander.jar): version 1.72
Java Assembler Tools, version 7.0 beta b02 (June 21, 2020)

I've updated this PR to include your suggested change.

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 think this version looks much better. A few nits with naming/style but not worth spending time on.

@dfuch
Copy link
Member

dfuch commented Sep 7, 2020

Hi Jaikiran,

I'll sponsor this for you when it is ready to integrate but I'd like to send it to our test system first.

best regards,
-- daniel

@jaikiran
Copy link
Member Author

jaikiran commented Sep 7, 2020

Thank you everyone for the reviews and thank you Daniel for sponsoring. I'll wait for an update from you on the test results, to intiate the integrate command.

@dfuch
Copy link
Member

dfuch commented Sep 7, 2020

Hi Jaikiran, the test results came back green.

best regards,

-- daniel

@jaikiran
Copy link
Member Author

jaikiran commented Sep 8, 2020

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Sep 8, 2020
@openjdk
Copy link

openjdk bot commented Sep 8, 2020

@jaikiran
Your change (at version 0d5d961) is now ready to be sponsored by a Committer.

@dfuch
Copy link
Member

dfuch commented Sep 8, 2020

/sponsor

@openjdk openjdk bot closed this Sep 8, 2020
@openjdk openjdk bot added integrated Pull request has been integrated and removed sponsor Pull request is ready to be sponsored ready Pull request is ready to be integrated rfr Pull request is ready for review labels Sep 8, 2020
@openjdk
Copy link

openjdk bot commented Sep 8, 2020

@dfuch @jaikiran Since your change was applied there have been 12 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

Pushed as commit 5dd1ead.

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

cushon pushed a commit to cushon/jdk that referenced this pull request Apr 2, 2021
It is supposed to be a no-op. As such, the stub files usually omit it.

Currently, it actually changes behavior in a bad way:
typetools/checker-framework#2995

Until that bug is fixed, this commit serves as a workaround.
asotona pushed a commit to asotona/jdk that referenced this pull request Oct 7, 2022
asotona pushed a commit to asotona/jdk that referenced this pull request Feb 6, 2023
gnu-andrew pushed a commit to gnu-andrew/jdk that referenced this pull request Apr 12, 2023
…itialized (openjdk#26)

Co-authored-by: Martin Balao <mbalao@redhat.com>
Reviewed-by: @franferrax, @gnu-andrew
caojoshua pushed a commit to caojoshua/jdk that referenced this pull request May 8, 2023
Avoid phi(null, n) from materializing.
robehn pushed a commit to robehn/jdk that referenced this pull request Aug 15, 2023
@jaikiran jaikiran deleted the 8252767 branch January 25, 2024 09:38
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 net net-dev@openjdk.org
6 participants