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-8317633: Modernize text.testlib.HexDumpReader #16075

Conversation

justin-curtis-lu
Copy link
Member

@justin-curtis-lu justin-curtis-lu commented Oct 6, 2023

Please review this PR which cleans up the static test utility class HexDumpReader.

This cleans up the code by replacing the nested ByteArrayBuilder class with HexFormat, and simplifies the File processing by using a stream. Changes were tested to ensure that the text tests are still getting equivalent ByteArrayInputStreams as before.


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-8317633: Modernize text.testlib.HexDumpReader (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 16075

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 6, 2023

👋 Welcome back jlu! 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 Oct 6, 2023
@openjdk
Copy link

openjdk bot commented Oct 6, 2023

@justin-curtis-lu The following label will be automatically applied to this pull request:

  • core-libs

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 pull request command.

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label Oct 6, 2023
@mlbridge
Copy link

mlbridge bot commented Oct 6, 2023

Webrevs

Copy link
Contributor

@LanceAndersen LanceAndersen left a comment

Choose a reason for hiding this comment

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

looks OK overall...

A couple minor comments below

}

// Converts a Hex dump file (File) into an InputStream containing bytes
public static InputStream getStreamFromHexDump(File hexFile) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add a comment of the expected format of the file passed to this method.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the review. Updated the documentation to describe the format that the hex dump file should be in, and examples.

@openjdk
Copy link

openjdk bot commented Oct 6, 2023

@justin-curtis-lu 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:

8317633: Modernize text.testlib.HexDumpReader

Reviewed-by: lancea, naoto, mli

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

  • f61499c: 8316608: Enable parallelism in vmTestbase/gc/vector tests
  • 3ff5a78: 8317693: Unused parameter to Tokens.Token.comment method
  • 508fa71: 8317736: Stream::handleReset locks twice
  • 1f06325: 8317471: ListFormat::parseObject() spec can be improved on parsePosition valid values
  • a07a4a3: 8317422: [JVMCI] concurrency issue in MethodData creation
  • 7ff1938: 8310727: C2: *_of() methods in PhaseIterGVN should use uint for the node index
  • a57ae7e: 8317594: G1: Refactor find_empty_from_idx_reverse
  • 6ddbfaa: 8317136: [AIX] Problem List runtime/jni/terminatedThread/TestTerminatedThread.java
  • 0cf1a55: 8317440: Lock rank checking fails when code root set is modified with the Servicelock held after JDK-8315503
  • bcc986b: 8317601: Windows build on WSL broken after JDK-8317340
  • ... and 13 more: https://git.openjdk.org/jdk/compare/a1c9587c27538bda3b0f6745d9c80ff4e1b9a77e...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.

➡️ 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 Oct 6, 2023
Comment on lines 63 to 65
String hexString = lines.stream().map(String::trim)
.map(s -> (s.contains("#")) ? s.substring(0, s.indexOf("#")).trim() : s)
.filter(s -> !s.isEmpty()).collect(Collectors.joining());
Copy link
Member

Choose a reason for hiding this comment

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

I think the common style is to wrap the line per each stream operation. Also, trim() can be done after removing # so that trimming is not necessary in that map operation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the review. Talked with Lance offline, and since none of the existing dump files actually use a non-leading comment, I changed the stream to only look for leading comments (removed ternary map operation).

As a result, I adjusted the documentation to state that a valid valid hex dump file format does not allow non-leading comments.

Comment on lines 58 to 60
} catch (IOException e) {
throw new RuntimeException(String.format("Utility class HexDumpReader" +
" threw %s when trying to read the file %s", e, hexFile.getName()));
Copy link
Member

Choose a reason for hiding this comment

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

It's OK as it is. It could simply throw that IOException which may be simpler.

Copy link
Member

@naotoj naotoj left a comment

Choose a reason for hiding this comment

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

LGTM

@justin-curtis-lu
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Oct 9, 2023

Going to push as commit 8e0686b.
Since your change was applied there have been 24 commits pushed to the master branch:

  • 5e8d893: 8317631: Refactor ChoiceFormat tests to use JUnit
  • f61499c: 8316608: Enable parallelism in vmTestbase/gc/vector tests
  • 3ff5a78: 8317693: Unused parameter to Tokens.Token.comment method
  • 508fa71: 8317736: Stream::handleReset locks twice
  • 1f06325: 8317471: ListFormat::parseObject() spec can be improved on parsePosition valid values
  • a07a4a3: 8317422: [JVMCI] concurrency issue in MethodData creation
  • 7ff1938: 8310727: C2: *_of() methods in PhaseIterGVN should use uint for the node index
  • a57ae7e: 8317594: G1: Refactor find_empty_from_idx_reverse
  • 6ddbfaa: 8317136: [AIX] Problem List runtime/jni/terminatedThread/TestTerminatedThread.java
  • 0cf1a55: 8317440: Lock rank checking fails when code root set is modified with the Servicelock held after JDK-8315503
  • ... and 14 more: https://git.openjdk.org/jdk/compare/a1c9587c27538bda3b0f6745d9c80ff4e1b9a77e...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Oct 9, 2023

@justin-curtis-lu Pushed as commit 8e0686b.

💡 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
Labels
core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated
4 participants