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

8316557: Make fields final in 'sun.util' package #15736

Closed
wants to merge 3 commits into from

Conversation

turbanoff
Copy link
Member

@turbanoff turbanoff commented Sep 14, 2023

A few classes in sun.util package have non-final fields which could easily be marked final.


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-8316557: Make fields final in 'sun.util' package (Enhancement - P5)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 15736

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 14, 2023

👋 Welcome back aturbanov! 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 bot commented Sep 14, 2023

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

  • core-libs
  • i18n

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.

@openjdk openjdk bot added core-libs core-libs-dev@openjdk.org i18n i18n-dev@openjdk.org labels Sep 14, 2023
@@ -73,7 +68,7 @@ public CharsetEncoder newEncoder() {

private final class PropertiesFileDecoder extends CharsetDecoder {

private CharsetDecoder cdUTF_8 = UTF_8.INSTANCE.newDecoder()
private final CharsetDecoder cdUTF_8 = UTF_8.INSTANCE.newDecoder()
Copy link
Member

Choose a reason for hiding this comment

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

Can be static as well.

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'm not sure. Why do you think so? CharsetDecoder is not thread-safe.

Copy link
Member

Choose a reason for hiding this comment

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

UTF8 decoder does not perform any internal state mutation during decoding; in addition, if this field is static final, the decoder's error actions are published when the class is initialized, while publishing in a final field does not guarantee the internal state of the charset is visible to other threads.

Copy link
Contributor

Choose a reason for hiding this comment

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

UTF8 decoder does not perform any internal state mutation during decoding;

Are you sure? I think CharsetDecoder::decode will modify the status field.

Copy link
Member

Choose a reason for hiding this comment

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

right, it does have a state field.

Copy link
Contributor

Choose a reason for hiding this comment

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

CharsetDecoder is specified to be not safe for use by multiple concurrent threads, would be too fragile to assume behavior of a specific implementation.

@turbanoff turbanoff changed the title [PATCH] Make fields final in 'sun.util' package 8316557: Make fields final in 'sun.util' package Sep 19, 2023
@openjdk openjdk bot added the rfr Pull request is ready for review label Sep 19, 2023
@mlbridge
Copy link

mlbridge bot commented Sep 19, 2023

Webrevs

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 23, 2023

@turbanoff This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@turbanoff
Copy link
Member Author

Can I get a review?

@@ -47,8 +45,8 @@
*/
public class CLDRCalendarDataProviderImpl extends CalendarDataProviderImpl {

private static Map<String, Integer> firstDay = new ConcurrentHashMap<>();
private static Map<String, Integer> minDays = new ConcurrentHashMap<>();
private static final Map<String, Integer> firstDay = new ConcurrentHashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

We might rename these fields to FIRST_DAY etc.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm. Usually CAPS naming is used only on immutable constants, but here we have mutable field. (See google style guide for example - https://google.github.io/styleguide/javaguide.html#s5.2.4-constant-names).
I like old naming approach.

@@ -60,7 +60,7 @@ public class CLDRLocaleProviderAdapter extends JRELocaleProviderAdapter {
private final LocaleDataMetaInfo nonBaseMetaInfo;

// parent locales map
private static volatile Map<Locale, Locale> parentLocalesMap;
private static final Map<Locale, Locale> parentLocalesMap;
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename to PARENT_LOCALES_MAP?

@@ -100,7 +100,7 @@ protected K normalizeKey(K key) {
}

private static class CacheEntry<K, V> extends SoftReference<V> {
Copy link
Contributor

Choose a reason for hiding this comment

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

The class itself might be final

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 think making classes final is out of scope of this PR.

@@ -31,9 +31,9 @@
package sun.util.locale;

public class StringTokenIterator {
Copy link
Contributor

Choose a reason for hiding this comment

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

The class may be final

Copy link
Contributor

@minborg minborg left a comment

Choose a reason for hiding this comment

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

LGTM. See comments though.

@openjdk
Copy link

openjdk bot commented Nov 13, 2023

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

8316557: Make fields final in 'sun.util' package

Reviewed-by: pminborg, naoto

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 862 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 Pull request is ready to be integrated label Nov 13, 2023
rename 'firstDay' to 'firstDays' to match 'minDays' naming
@@ -47,8 +45,8 @@
*/
public class CLDRCalendarDataProviderImpl extends CalendarDataProviderImpl {

private static Map<String, Integer> firstDay = new ConcurrentHashMap<>();
private static Map<String, Integer> minDays = new ConcurrentHashMap<>();
private static final Map<String, Integer> firstDays = new ConcurrentHashMap<>();
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is correct. "First Day" is the first day of the week and should not be plural.

Copy link
Contributor

Choose a reason for hiding this comment

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

The map contains several entries so I think the plural form is appropriate here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Current naming highlights the difference in values in this maps: FIRST_DAY_OF_WEEK vs MINIMAL_DAYS_IN_FIRST_WEEK.
I like this approach.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe firstDayMap/minDaysMap would clarify more, but either way is fine with me

"First Day" is the first day of the week and should not be plural
@turbanoff turbanoff requested a review from naotoj November 17, 2023 08:27
@turbanoff
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Nov 20, 2023

Going to push as commit 6c5e15c.
Since your change was applied there have been 867 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Nov 20, 2023

@turbanoff Pushed as commit 6c5e15c.

💡 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 i18n i18n-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

6 participants