-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Conversation
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 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 |
@jaikiran The following labels will be automatically applied to this pull request: |
FYI - I am an "author" in the JDK project and have requested for linking this github account to my OpenJDK account ( |
/solves 8252767 |
@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. |
Webrevs
|
* when already connected | ||
* @run testng URLConnectionTest | ||
*/ | ||
public class URLConnectionTest { |
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 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)
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.
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?
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 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(); |
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 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.
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 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.
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.
Overall, this looks good. I added a few minor test related comments.
final URLConnection conn = url.openConnection(); | ||
conn.connect(); | ||
try { | ||
conn.setRequestProperty("foo", "bar"); |
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.
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.
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.
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:
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.
LGTM.
@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:
Since the source branch of this PR was last updated there have been 12 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 automatic rebasing, please merge 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 |
} catch (IllegalStateException ise) { | ||
// expected | ||
} | ||
} |
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.
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.
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.
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.
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 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 |
Slightly OT - but I think this |
@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. |
@jaikiran For what it's worth, this is how the interaction was designed. When an author that isn't an OpenJDK Committer issues the If the author didn't have to issue the |
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. |
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.
LGTM
failed++; | ||
} catch (NullPointerException e) { /* Expected */ } | ||
conn.addRequestProperty(null, "hello"); | ||
Assert.fail("addRequestProperty on " + conn.getClass().getName() |
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.
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
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.
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.
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 version looks much better. A few nits with naming/style but not worth spending time on.
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, |
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. |
Hi Jaikiran, the test results came back green. best regards, -- daniel |
/integrate |
/sponsor |
@dfuch @jaikiran Since your change was applied there have been 12 commits pushed to the
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. |
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.
…itialized (openjdk#26) Co-authored-by: Martin Balao <mbalao@redhat.com> Reviewed-by: @franferrax, @gnu-andrew
Avoid phi(null, n) from materializing.
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 aIllegalAccessError
instead of aIllegalStateException
. 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
Issue
Reviewers
Download
$ git fetch https://git.openjdk.java.net/jdk pull/26/head:pull/26
$ git checkout pull/26