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-8257401: Use switch expressions in jdk.internal.net.http and java.net.http #1364

Closed
wants to merge 3 commits into from
Closed

Conversation

@amCap1712
Copy link
Contributor

@amCap1712 amCap1712 commented Nov 21, 2020

Hi!
Kindly review this patch to replace switch statements with switch expressions (where it makes sense) in the http client modules. The rationale is to improve readability of the code.
Regards,
Kartik


Progress

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

Issue

  • JDK-8257401: Use switch expressions in jdk.internal.net.http and java.net.http

Reviewers

Download

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

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Nov 21, 2020

👋 Welcome back amCap1712! 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
Copy link

@openjdk openjdk bot commented Nov 21, 2020

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

  • net
  • 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.

@amCap1712 amCap1712 changed the title Use switch expressions in jdk.internal.net.http and java.net.http JDK-8257401: Use switch expressions in jdk.internal.net.http and java.net.http Nov 30, 2020
@openjdk openjdk bot added the rfr label Nov 30, 2020
@mlbridge
Copy link

@mlbridge mlbridge bot commented Nov 30, 2020

Webrevs

@johnshajiang
Copy link
Member

@johnshajiang johnshajiang commented Dec 1, 2020

Just a question.
Do we have clear guideline or requirement for using this new lang feature?
We know there are a lot of old switch-case blocks in the existing codes,
including source codes and test codes.

return "MAX_HEADER_LIST_SIZE";
}
return "unknown parameter";
return switch (i + 1) {
Copy link
Contributor

@pconcannon pconcannon Dec 1, 2020

Choose a reason for hiding this comment

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

Hi Kartik. I think it would improve the readability for each of the switch/case expressions if you tab aligned each of the cases, and place the default case on its own line e.g.

    return switch (i + 1) {
        case HEADER_TABLE_SIZE      -> "HEADER_TABLE_SIZE";
        case ENABLE_PUSH            -> "ENABLE_PUSH";
        case MAX_CONCURRENT_STREAMS -> "MAX_CONCURRENT_STREAMS";
        case INITIAL_WINDOW_SIZE    -> "INITIAL_WINDOW_SIZE";
        case MAX_FRAME_SIZE         -> "MAX_FRAME_SIZE";
        case MAX_HEADER_LIST_SIZE   -> "MAX_HEADER_LIST_SIZE";

        default -> "unknown parameter";
    };

@dfuch
Copy link
Member

@dfuch dfuch commented Dec 1, 2020

Do we have clear guideline or requirement for using this new lang feature?
We know there are a lot of old switch-case blocks in the existing codes,
including source codes and test codes.

@johnshajiang I don't think we have any global guideline but in this specific case I agree that using switch expressions as proposed is making the code generally more readable, with maybe a few cases where it might not have improved readability as much (for instance I'm not a big fan of line 54 in that file: https://github.com/openjdk/jdk/pull/1364/files#diff-ae0f662913a65511f983a3f0f9a98b708c11906a6f87aa4c96ab6fc7abf5ae9f )

best regards,

-- daniel

@openjdk openjdk bot removed the rfr label Dec 2, 2020
Copy link
Member

@ChrisHegarty ChrisHegarty left a comment

I think that the actual source changes look good.

A few notes:

  1. there are whitespace issues. jcheck is failing.
  2. Please do not force push - just push. Force push messes up prior comments in the thread.

case MAX_FRAME_SIZE -> "MAX_FRAME_SIZE";
case MAX_HEADER_LIST_SIZE -> "MAX_HEADER_LIST_SIZE";

default -> "unknown parameter";
Copy link
Member

@dfuch dfuch Dec 2, 2020

Choose a reason for hiding this comment

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

Check failure on line 81 in src/java.net.http/share/classes/jdk/internal/net/http/frame/SettingsFrame.java
openjdk / jcheck

Whitespace error

Column 0: trailing whitespace
...

WRT to whitespace errors detected by jcheck, note that you can fix them by running the script:

make/scripts/normalizer.pl

on this file.

Copy link
Contributor Author

@amCap1712 amCap1712 Dec 2, 2020

Choose a reason for hiding this comment

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

That's handy. Thanks!

case HEADER_FOUND_CR, HEADER_FOUND_LF -> resumeOrLF(input);
case HEADER_FOUND_CR_LF -> resumeOrSecondCR(input);
case HEADER_FOUND_CR_LF_CR -> resumeOrEndHeaders(input);
case INITIAL -> state = State.STATUS_LINE;
Copy link
Contributor

@pconcannon pconcannon Dec 2, 2020

Choose a reason for hiding this comment

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

Looks good. Although, I think you can improve it further if you align the lambda operators as well

Copy link
Contributor Author

@amCap1712 amCap1712 Dec 2, 2020

Choose a reason for hiding this comment

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

Yes right. Just noticed I had missed that. Fixed in latest commit :)

Copy link
Contributor

@pconcannon pconcannon Dec 2, 2020

Choose a reason for hiding this comment

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

Looks much better, Kartik. Thanks

@openjdk
Copy link

@openjdk openjdk bot commented Dec 2, 2020

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

8257401: Use switch expressions in jdk.internal.net.http and java.net.http

Reviewed-by: chegar, dfuchs, pconcannon

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 176 new commits pushed to the master branch:

  • 86b6575: 8257574: C2: "failed: parsing found no loops but there are some" assert failure
  • dede01e: 8257622: MemoryAccess methods are missing @forceinline annotations
  • 1d2d981: 8257423: [PPC64] Support -XX:-UseInlineCaches
  • feabdde: 8251843: jfr/tool/TestPrintJSON.java fails intermittently
  • c6f93ec: 8257707: Fix incorrect format string in Http1HeaderParser
  • fbdc187: 8257624: C2: PhaseMacroExpand::eliminate_macro_nodes() crashes on out-of-bounds access into macro node array
  • fd6756e: 8257634: C2: Introduce IncrementalInliningForceCleanup diagnostic flag
  • af6b7f9: 8257743: Minimal build on AArch64 failed with --disable-precompiled-headers
  • d6dd440: 8256264: Printed GlyphVector outline with low DPI has bad quality on Windows
  • 2b4a423: 8255542: Attribute length of Module, ModulePackages and other attributes is ignored
  • ... and 166 more: https://git.openjdk.java.net/jdk/compare/0d91f0a1df2dbb484e964efa4f1a9500eab799fe...master

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.

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, @dfuch) 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).

@amCap1712
Copy link
Contributor Author

@amCap1712 amCap1712 commented Dec 2, 2020

@ChrisHegarty Thanks for the review. I'll keep in mind not to use force push again.

dfuch
dfuch approved these changes Dec 2, 2020
@amCap1712
Copy link
Contributor Author

@amCap1712 amCap1712 commented Dec 4, 2020

@pconcannon, If everything is in order, can you please approve the changes on Github. I'll then issue the integrate command. Thanks.

@pconcannon
Copy link
Contributor

@pconcannon pconcannon commented Dec 4, 2020

@pconcannon, If everything is in order, can you please approve the changes on Github. I'll then issue the integrate command. Thanks.

Hi @amCap1712, you will have to /integrate first, and then afterwards I will sponsor

@amCap1712
Copy link
Contributor Author

@amCap1712 amCap1712 commented Dec 4, 2020

/integrate

@openjdk openjdk bot added the sponsor label Dec 4, 2020
@openjdk
Copy link

@openjdk openjdk bot commented Dec 4, 2020

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

@amCap1712
Copy link
Contributor Author

@amCap1712 amCap1712 commented Dec 4, 2020

/reviewer credit @pconcannon

@openjdk
Copy link

@openjdk openjdk bot commented Dec 4, 2020

@amCap1712
Reviewer pconcannon successfully credited.

@pconcannon
Copy link
Contributor

@pconcannon pconcannon commented Dec 4, 2020

/sponsor

@openjdk openjdk bot closed this Dec 4, 2020
@openjdk
Copy link

@openjdk openjdk bot commented Dec 4, 2020

@pconcannon @amCap1712 Since your change was applied there have been 176 commits pushed to the master branch:

  • 86b6575: 8257574: C2: "failed: parsing found no loops but there are some" assert failure
  • dede01e: 8257622: MemoryAccess methods are missing @forceinline annotations
  • 1d2d981: 8257423: [PPC64] Support -XX:-UseInlineCaches
  • feabdde: 8251843: jfr/tool/TestPrintJSON.java fails intermittently
  • c6f93ec: 8257707: Fix incorrect format string in Http1HeaderParser
  • fbdc187: 8257624: C2: PhaseMacroExpand::eliminate_macro_nodes() crashes on out-of-bounds access into macro node array
  • fd6756e: 8257634: C2: Introduce IncrementalInliningForceCleanup diagnostic flag
  • af6b7f9: 8257743: Minimal build on AArch64 failed with --disable-precompiled-headers
  • d6dd440: 8256264: Printed GlyphVector outline with low DPI has bad quality on Windows
  • 2b4a423: 8255542: Attribute length of Module, ModulePackages and other attributes is ignored
  • ... and 166 more: https://git.openjdk.java.net/jdk/compare/0d91f0a1df2dbb484e964efa4f1a9500eab799fe...master

Your commit was automatically rebased without conflicts.

Pushed as commit ac54900.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
5 participants