Skip to content

Commit 6c5e15c

Browse files
author
Andrey Turbanov
committed
8316557: Make fields final in 'sun.util' package
Reviewed-by: pminborg, naoto
1 parent de51aa1 commit 6c5e15c

10 files changed

+29
-40
lines changed

src/java.base/share/classes/sun/util/PreHashedMap.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2004, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -243,7 +243,7 @@ public boolean hasNext() {
243243

244244
public Map.Entry<String,V> next() {
245245
return new Map.Entry<String,V>() {
246-
String k = i.next();
246+
final String k = i.next();
247247
public String getKey() { return k; }
248248
public V getValue() { return get(k); }
249249
public int hashCode() {

src/java.base/share/classes/sun/util/PropertyResourceBundleCharset.java

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -35,7 +35,6 @@
3535
import java.nio.charset.CharsetEncoder;
3636
import java.nio.charset.CoderResult;
3737
import java.nio.charset.CodingErrorAction;
38-
import java.nio.charset.StandardCharsets;
3938
import java.util.Objects;
4039

4140
/**
@@ -45,17 +44,13 @@
4544
*/
4645
public class PropertyResourceBundleCharset extends Charset {
4746

48-
private boolean strictUTF8 = false;
47+
private final boolean strictUTF8;
4948

5049
public PropertyResourceBundleCharset(boolean strictUTF8) {
51-
this(PropertyResourceBundleCharset.class.getCanonicalName(), null);
50+
super(PropertyResourceBundleCharset.class.getCanonicalName(), null);
5251
this.strictUTF8 = strictUTF8;
5352
}
5453

55-
public PropertyResourceBundleCharset(String canonicalName, String[] aliases) {
56-
super(canonicalName, aliases);
57-
}
58-
5954
@Override
6055
public boolean contains(Charset cs) {
6156
return false;
@@ -73,7 +68,7 @@ public CharsetEncoder newEncoder() {
7368

7469
private final class PropertiesFileDecoder extends CharsetDecoder {
7570

76-
private CharsetDecoder cdUTF_8 = UTF_8.INSTANCE.newDecoder()
71+
private final CharsetDecoder cdUTF_8 = UTF_8.INSTANCE.newDecoder()
7772
.onMalformedInput(CodingErrorAction.REPORT)
7873
.onUnmappableCharacter(CodingErrorAction.REPORT);
7974
private CharsetDecoder cdISO_8859_1 = null;

src/java.base/share/classes/sun/util/ResourceBundleEnumeration.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2005, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -36,9 +36,9 @@
3636
*/
3737
public class ResourceBundleEnumeration implements Enumeration<String> {
3838

39-
Set<String> set;
40-
Iterator<String> iterator;
41-
Enumeration<String> enumeration; // may remain null
39+
private final Set<String> set;
40+
private final Iterator<String> iterator;
41+
private final Enumeration<String> enumeration; // may remain null
4242

4343
/**
4444
* Constructs a resource bundle enumeration.

src/java.base/share/classes/sun/util/calendar/LocalGregorianCalendar.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ private static boolean isValidEra(Era newEra, Era[] eras) {
6060
return true;
6161
}
6262

63-
private String name;
64-
private Era[] eras;
63+
private final String name;
64+
private final Era[] eras;
6565

6666
// Used within java.time and java.util
6767
public static final class Date extends BaseCalendar.Date {

src/java.base/share/classes/sun/util/calendar/ZoneInfoFile.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ private ZoneInfoFile() {
210210

211211
private static String versionId;
212212
private static final Map<String, ZoneInfo> zones = new ConcurrentHashMap<>();
213-
private static Map<String, String> aliases = new HashMap<>();
213+
private static final Map<String, String> aliases = new HashMap<>();
214214

215215
private static byte[][] ruleArray;
216216
private static String[] regions;
@@ -219,7 +219,7 @@ private ZoneInfoFile() {
219219
// Flag for supporting JDK backward compatible IDs, such as "EST".
220220
private static final boolean USE_OLDMAPPING;
221221

222-
private static String[][] oldMappings = new String[][] {
222+
private static final String[][] oldMappings = new String[][] {
223223
{ "ACT", "Australia/Darwin" },
224224
{ "AET", "Australia/Sydney" },
225225
{ "AGT", "America/Argentina/Buenos_Aires" },

src/java.base/share/classes/sun/util/cldr/CLDRCalendarDataProviderImpl.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -27,14 +27,12 @@
2727

2828
import static sun.util.locale.provider.LocaleProviderAdapter.Type;
2929

30-
import java.util.Arrays;
3130
import java.util.Map;
3231
import java.util.Locale;
3332
import java.util.Set;
3433
import java.util.Optional;
3534
import java.util.concurrent.ConcurrentHashMap;
3635
import sun.util.locale.provider.LocaleProviderAdapter;
37-
import sun.util.locale.provider.LocaleResources;
3836
import sun.util.locale.provider.CalendarDataProviderImpl;
3937
import sun.util.locale.provider.CalendarDataUtility;
4038

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

50-
private static Map<String, Integer> firstDay = new ConcurrentHashMap<>();
51-
private static Map<String, Integer> minDays = new ConcurrentHashMap<>();
48+
private static final Map<String, Integer> firstDay = new ConcurrentHashMap<>();
49+
private static final Map<String, Integer> minDays = new ConcurrentHashMap<>();
5250

5351
public CLDRCalendarDataProviderImpl(Type type, Set<String> langtags) {
5452
super(type, langtags);

src/java.base/share/classes/sun/util/cldr/CLDRLocaleProviderAdapter.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -60,7 +60,7 @@ public class CLDRLocaleProviderAdapter extends JRELocaleProviderAdapter {
6060
private final LocaleDataMetaInfo nonBaseMetaInfo;
6161

6262
// parent locales map
63-
private static volatile Map<Locale, Locale> parentLocalesMap;
63+
private static final Map<Locale, Locale> parentLocalesMap;
6464
// cache to hold locale to locale mapping for language aliases.
6565
private static final Map<Locale, Locale> langAliasesCache;
6666
// cache the available locales

src/java.base/share/classes/sun/util/locale/LocaleObjectCache.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -100,7 +100,7 @@ protected K normalizeKey(K key) {
100100
}
101101

102102
private static class CacheEntry<K, V> extends SoftReference<V> {
103-
private K key;
103+
private final K key;
104104

105105
CacheEntry(K key, V value, ReferenceQueue<V> queue) {
106106
super(value, queue);

src/java.base/share/classes/sun/util/locale/LocaleSyntaxException.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -36,7 +36,7 @@ public class LocaleSyntaxException extends Exception {
3636
@java.io.Serial
3737
private static final long serialVersionUID = 1L;
3838

39-
private int index = -1;
39+
private final int index;
4040

4141
public LocaleSyntaxException(String msg) {
4242
this(msg, 0);

src/java.base/share/classes/sun/util/locale/StringTokenIterator.java

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -31,9 +31,9 @@
3131
package sun.util.locale;
3232

3333
public class StringTokenIterator {
34-
private String text;
35-
private String dlms; // null if a single char delimiter
36-
private char delimiterChar; // delimiter if a single char delimiter
34+
private final String text;
35+
private final String dlms; // null if a single char delimiter
36+
private final char delimiterChar; // delimiter if a single char delimiter
3737

3838
private String token;
3939
private int start;
@@ -44,7 +44,9 @@ public StringTokenIterator(String text, String dlms) {
4444
this.text = text;
4545
if (dlms.length() == 1) {
4646
delimiterChar = dlms.charAt(0);
47+
this.dlms = null;
4748
} else {
49+
delimiterChar = 0;
4850
this.dlms = dlms;
4951
}
5052
setStart(0);
@@ -99,12 +101,6 @@ public StringTokenIterator setStart(int offset) {
99101
return this;
100102
}
101103

102-
public StringTokenIterator setText(String text) {
103-
this.text = text;
104-
setStart(0);
105-
return this;
106-
}
107-
108104
private int nextDelimiter(int start) {
109105
int textlen = this.text.length();
110106
if (dlms == null) {

0 commit comments

Comments
 (0)