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

8255405: sun/net/ftp/imp/FtpClient uses SimpleDateFormat in not thread-safe manner #867

Closed
wants to merge 6 commits into from

Conversation

@iignatev
Copy link
Member

@iignatev iignatev commented Oct 26, 2020

Hi all,

could you please review this small and trivial fix?

sun/net/ftp/imp/FtpClient::dateFormats is an array of SimpleDateFormat which are shared among all instances of FtpClient. the fact that SimpleDateFormat isn't thread-safe rendersFtpClient to be non-thread-safe as well. the patch makes the only usage of dateFormats array, parseRfc3659TimeValue method, synchronized.

the problem was reported in #776

Thanks,
-- Igor


Progress

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

Testing

Linux x32 Linux x64 Windows x64 macOS x64
Build ✔️ (1/1 passed) ✔️ (5/5 passed) ✔️ (2/2 passed) ✔️ (2/2 passed)
Test (tier1) ✔️ (9/9 passed) ✔️ (9/9 passed) ✔️ (9/9 passed)

Issue

  • JDK-8255405: sun/net/ftp/imp/FtpClient uses SimpleDateFormat in not thread-safe manner

Reviewers

Download

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

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Oct 26, 2020

👋 Welcome back iignatyev! 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 label Oct 26, 2020
@openjdk
Copy link

@openjdk openjdk bot commented Oct 26, 2020

@iignatev The following label 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 pull request command.

@openjdk openjdk bot added the net label Oct 26, 2020
@mlbridge
Copy link

@mlbridge mlbridge bot commented Oct 26, 2020

Webrevs

@iignatev
Copy link
Member Author

@iignatev iignatev commented Oct 27, 2020

Hi Chris,

I've actually thought about DateTimeFormatter when I was fixing 8255078 / #776, but when I noticed MDTMformats and decided to reuse it. anyhow, I have updated FtpClient to use DateTimeFormatter instead of SimpleDateFormat. testing this, I realized that the test added by 8255078 didn't really produce the strings in accordance with RFC 3659; so this PR fixes that as well.

Thanks,
-- Igor

Date result = null;
try {
var d = LocalDateTime.parse(s, RFC3659_DATETIME_FORMAT);
result = Date.from(d.atZone(ZoneOffset.systemDefault()).toInstant());
Copy link
Member

@dfuch dfuch Oct 28, 2020

Choose a reason for hiding this comment

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

Should this be ZoneOffset.UTC rather than System default? I thought the date returned by the server were supposed to be in GMT.

Copy link
Member

@rhyadav rhyadav Oct 28, 2020

Choose a reason for hiding this comment

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

ZoneOffset.UTC should return GMT as was the case with SimpleDateFormat before the changes.

Copy link
Member Author

@iignatev iignatev Oct 28, 2020

Choose a reason for hiding this comment

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

right, thanks for spotting that! I don't know what I was thinking when used systemDefault here and when was also got tricked by my own test 🤦

@rhyadav
Copy link
Member

@rhyadav rhyadav commented Oct 28, 2020

LGTM!

@openjdk
Copy link

@openjdk openjdk bot commented Oct 28, 2020

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

8255405: sun/net/ftp/imp/FtpClient uses SimpleDateFormat in not thread-safe manner

Reviewed-by: chegar, ryadav, dfuchs

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 47 new 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 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 label Oct 28, 2020
dfuch
dfuch approved these changes Oct 28, 2020
@iignatev
Copy link
Member Author

@iignatev iignatev commented Oct 28, 2020

Daniel, Rahul, Chris, thank you for your reviews!

/integrate

@openjdk openjdk bot closed this Oct 28, 2020
@openjdk openjdk bot added integrated and removed ready rfr labels Oct 28, 2020
@openjdk
Copy link

@openjdk openjdk bot commented Oct 28, 2020

@iignatev Since your change was applied there have been 55 commits pushed to the master branch:

  • d82a6dc: 8255438: [Vector API] More instructs in x86.ad should use legacy mode for code-gen
  • 1a5e6c9: 8253101: Clean up CallStaticJavaNode EA flags
  • a7595b2: 8250669: Running JMH micros is broken after JDK-8248135
  • edd1988: 8255530: Additional cleanup after JDK-8235710 (elliptic curve removal)
  • 790d6e2: 8255533: Incorrect javadoc in DateTimeFormatterBuilder.appendPattern() for 'uu'/'yy'
  • 3f20612: 8255555: Bad copyright headers in SocketChannelCompare.java SocketChannelConnectionSetup.java UnixSocketChannelReadWrite.java
  • 42fc158: 8253939: [TESTBUG] Increase coverage of the cgroups detection code
  • 01eb690: 8255554: Bad copyright header in AbstractFileSystemProvider.java
  • 1215b1a: 8255457: Shenandoah: cleanup ShenandoahMarkTask
  • af33e16: 8255441: Cleanup ciEnv/jvmciEnv::lookup_method-s
  • ... and 45 more: https://git.openjdk.java.net/jdk/compare/fa64477c820ecaa33b682214a02b82ab8a6f0686...master

Your commit was automatically rebased without conflicts.

Pushed as commit 7e305ad.

💡 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
4 participants