-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8316557: Make fields final in 'sun.util' package #15736
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /* | ||
| * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. | ||
| * Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved. | ||
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| * | ||
| * This code is free software; you can redistribute it and/or modify it | ||
|
|
@@ -27,14 +27,12 @@ | |
|
|
||
| import static sun.util.locale.provider.LocaleProviderAdapter.Type; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Map; | ||
| import java.util.Locale; | ||
| import java.util.Set; | ||
| import java.util.Optional; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import sun.util.locale.provider.LocaleProviderAdapter; | ||
| import sun.util.locale.provider.LocaleResources; | ||
| import sun.util.locale.provider.CalendarDataProviderImpl; | ||
| import sun.util.locale.provider.CalendarDataUtility; | ||
|
|
||
|
|
@@ -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<>(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might rename these fields to FIRST_DAY etc.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). |
||
| private static final Map<String, Integer> minDays = new ConcurrentHashMap<>(); | ||
|
|
||
| public CLDRCalendarDataProviderImpl(Type type, Set<String> langtags) { | ||
| super(type, langtags); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /* | ||
| * Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved. | ||
| * Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved. | ||
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| * | ||
| * This code is free software; you can redistribute it and/or modify it | ||
|
|
@@ -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; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename to PARENT_LOCALES_MAP? |
||
| // cache to hold locale to locale mapping for language aliases. | ||
| private static final Map<Locale, Locale> langAliasesCache; | ||
| // cache the available locales | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /* | ||
| * Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved. | ||
| * Copyright (c) 2010, 2023, Oracle and/or its affiliates. All rights reserved. | ||
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| * | ||
| * This code is free software; you can redistribute it and/or modify it | ||
|
|
@@ -100,7 +100,7 @@ protected K normalizeKey(K key) { | |
| } | ||
|
|
||
| private static class CacheEntry<K, V> extends SoftReference<V> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The class itself might be
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think making classes |
||
| private K key; | ||
| private final K key; | ||
|
|
||
| CacheEntry(K key, V value, ReferenceQueue<V> queue) { | ||
| super(value, queue); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /* | ||
| * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. | ||
| * Copyright (c) 2010, 2023, Oracle and/or its affiliates. All rights reserved. | ||
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| * | ||
| * This code is free software; you can redistribute it and/or modify it | ||
|
|
@@ -31,9 +31,9 @@ | |
| package sun.util.locale; | ||
|
|
||
| public class StringTokenIterator { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The class may be |
||
| private String text; | ||
| private String dlms; // null if a single char delimiter | ||
| private char delimiterChar; // delimiter if a single char delimiter | ||
| private final String text; | ||
| private final String dlms; // null if a single char delimiter | ||
| private final char delimiterChar; // delimiter if a single char delimiter | ||
|
|
||
| private String token; | ||
| private int start; | ||
|
|
@@ -44,7 +44,9 @@ public StringTokenIterator(String text, String dlms) { | |
| this.text = text; | ||
| if (dlms.length() == 1) { | ||
| delimiterChar = dlms.charAt(0); | ||
| this.dlms = null; | ||
| } else { | ||
| delimiterChar = 0; | ||
| this.dlms = dlms; | ||
| } | ||
| setStart(0); | ||
|
|
@@ -99,12 +101,6 @@ public StringTokenIterator setStart(int offset) { | |
| return this; | ||
| } | ||
|
|
||
| public StringTokenIterator setText(String text) { | ||
| this.text = text; | ||
| setStart(0); | ||
| return this; | ||
| } | ||
|
|
||
| private int nextDelimiter(int start) { | ||
| int textlen = this.text.length(); | ||
| if (dlms == null) { | ||
|
|
||
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.
Can be static as well.
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'm not sure. Why do you think so? CharsetDecoder is not thread-safe.
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.
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.
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.
Are you sure? I think
CharsetDecoder::decodewill modify thestatusfield.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.
right, it does have a
statefield.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.
CharsetDecoder is specified to be not safe for use by multiple concurrent threads, would be too fragile to assume behavior of a specific implementation.