Skip to content

Commit 94e08c8

Browse files
author
duke
committedJan 9, 2024
Automatic merge of jdk:master into master
2 parents 550979f + 376051a commit 94e08c8

File tree

1 file changed

+81
-10
lines changed

1 file changed

+81
-10
lines changed
 

‎src/java.base/share/classes/java/util/Locale.java

+81-10
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import java.io.ObjectOutputStream;
4646
import java.io.ObjectStreamField;
4747
import java.io.Serializable;
48+
import java.text.DateFormat;
4849
import java.text.MessageFormat;
4950
import java.util.concurrent.ConcurrentHashMap;
5051
import java.util.spi.LocaleNameProvider;
@@ -258,6 +259,74 @@
258259
* locales. For example, {@code Locale.US} is the {@code Locale} object
259260
* for the United States.
260261
*
262+
* <h3><a id="default_locale">Default Locale</a></h3>
263+
*
264+
* <p>The default Locale is provided for any locale-sensitive methods if no
265+
* {@code Locale} is explicitly specified as an argument, such as
266+
* {@link DateFormat#getInstance()}. The default Locale is determined at startup
267+
* of the Java runtime and established in the following three phases:
268+
* <ol>
269+
* <li>The locale-related system properties listed below are established from the
270+
* host environment. Some system properties (except for {@code user.language}) may
271+
* not have values from the host environment.
272+
* <table class="striped">
273+
* <caption style="display:none">Shows property keys and associated values</caption>
274+
* <thead>
275+
* <tr><th scope="col">Locale-related System Properties Key</th>
276+
* <th scope="col">Description</th></tr>
277+
* </thead>
278+
* <tbody>
279+
* <tr><th scope="row">{@systemProperty user.language}</th>
280+
* <td>{@link ##def_language language} for the default Locale,
281+
* such as "en" (English)</td></tr>
282+
* <tr><th scope="row">{@systemProperty user.script}</th>
283+
* <td>{@link ##def_script script} for the default Locale,
284+
* such as "Latn" (Latin)</td></tr>
285+
* <tr><th scope="row">{@systemProperty user.country}</th>
286+
* <td>{@link ##def_region country} for the default Locale,
287+
* such as "US" (United States)</td></tr>
288+
* <tr><th scope="row">{@systemProperty user.variant}</th>
289+
* <td>{@link ##def_variant variant} for the default Locale,
290+
* such as "POSIX"</td></tr>
291+
* <tr><th scope="row">{@systemProperty user.extensions}</th>
292+
* <td>{@link ##def_extensions extensions} for the default Locale,
293+
* such as "u-ca-japanese" (Japanese Calendar)</td></tr>
294+
* </tbody>
295+
* </table>
296+
* </li>
297+
* <li>The values of these system properties can be overridden by values designated
298+
* at startup time. If the overriding value of the {@code user.extensions} property
299+
* is unparsable, it is ignored. The overriding values of other properties are not
300+
* checked for syntax or validity and are used directly in the default Locale.
301+
* (Typically, system property values can be provided using the {@code -D} command-line
302+
* option of a launcher. For example, specifying {@code -Duser.extensions=foobarbaz}
303+
* results in a default Locale with no extensions, while specifying
304+
* {@code -Duser.language=foobarbaz} results in a default Locale whose language is
305+
* "foobarbaz".)
306+
* </li>
307+
* <li>The default {@code Locale} instance is constructed from the values of these
308+
* system properties.
309+
* </li>
310+
* </ol>
311+
* <p>Altering the system property values with {@link System#setProperties(Properties)}/
312+
* {@link System#setProperty(String, String)} has no effect on the default Locale.
313+
* <p>Once the default Locale is established, applications can query the default
314+
* Locale with {@link #getDefault()} and change it with {@link #setDefault(Locale)}.
315+
* If the default Locale is changed with {@link #setDefault(Locale)}, the corresponding
316+
* system properties are not altered. It is not recommended that applications read
317+
* these system properties and parse or interpret them as their values may be out of date.
318+
*
319+
* <p>There are finer-grained default Locales specific for each {@link Locale.Category}.
320+
* These category specific default Locales can be queried by {@link #getDefault(Category)},
321+
* and set by {@link #setDefault(Category, Locale)}. Construction of these category
322+
* specific default Locales are determined by the corresponding system properties,
323+
* which consist of the base system properties as listed above, suffixed by either
324+
* {@code ".display"} or {@code ".format"} depending on the category. For example,
325+
* the value of the {@code user.language.display} system property will be used in the
326+
* {@code language} part of the default Locale for the {@link Locale.Category#DISPLAY}
327+
* category. In the absence of category specific system properties, the "category-less"
328+
* system properties are used, such as {@code user.language} in the previous example.
329+
*
261330
* <h3><a id="LocaleMatching">Locale Matching</a></h3>
262331
*
263332
* <p>If an application or a system is internationalized and provides localized
@@ -984,14 +1053,14 @@ public int hashCode() {
9841053
}
9851054

9861055
/**
987-
* Gets the current value of the default locale for this instance
988-
* of the Java Virtual Machine.
1056+
* Gets the current value of the {@link ##default_locale default locale} for
1057+
* this instance of the Java Virtual Machine.
9891058
* <p>
9901059
* The Java Virtual Machine sets the default locale during startup
9911060
* based on the host environment. It is used by many locale-sensitive
9921061
* methods if no locale is explicitly specified.
9931062
* It can be changed using the
994-
* {@link #setDefault(java.util.Locale) setDefault} method.
1063+
* {@link #setDefault(Locale)} method.
9951064
*
9961065
* @return the default locale for this instance of the Java Virtual Machine
9971066
*/
@@ -1001,13 +1070,13 @@ public static Locale getDefault() {
10011070
}
10021071

10031072
/**
1004-
* Gets the current value of the default locale for the specified Category
1005-
* for this instance of the Java Virtual Machine.
1073+
* Gets the current value of the {@link ##default_locale default locale} for
1074+
* the specified Category for this instance of the Java Virtual Machine.
10061075
* <p>
10071076
* The Java Virtual Machine sets the default locale during startup based
10081077
* on the host environment. It is used by many locale-sensitive methods
10091078
* if no locale is explicitly specified. It can be changed using the
1010-
* setDefault(Locale.Category, Locale) method.
1079+
* {@link #setDefault(Locale.Category, Locale)} method.
10111080
*
10121081
* @param category the specified category to get the default locale
10131082
* @throws NullPointerException if category is null
@@ -1108,8 +1177,9 @@ private static Optional<LocaleExtensions> getDefaultExtensions(String extensions
11081177
}
11091178

11101179
/**
1111-
* Sets the default locale for this instance of the Java Virtual Machine.
1112-
* This does not affect the host locale.
1180+
* Sets the {@link ##default_locale default locale} for
1181+
* this instance of the Java Virtual Machine. This does not affect the
1182+
* host locale.
11131183
* <p>
11141184
* If there is a security manager, its {@code checkPermission}
11151185
* method is called with a {@code PropertyPermission("user.language", "write")}
@@ -1142,8 +1212,9 @@ public static synchronized void setDefault(Locale newLocale) {
11421212
}
11431213

11441214
/**
1145-
* Sets the default locale for the specified Category for this instance
1146-
* of the Java Virtual Machine. This does not affect the host locale.
1215+
* Sets the {@link ##default_locale default locale} for the specified
1216+
* Category for this instance of the Java Virtual Machine. This does
1217+
* not affect the host locale.
11471218
* <p>
11481219
* If there is a security manager, its checkPermission method is called
11491220
* with a PropertyPermission("user.language", "write") permission before

0 commit comments

Comments
 (0)
Please sign in to comment.