<i18n dev> RFR: 8039165: [Doc] MessageFormat null locale generates NullPointerException

Naoto Sato naoto at openjdk.org
Mon Jul 17 22:01:11 UTC 2023


On Mon, 17 Jul 2023 21:04:48 GMT, Justin Lu <jlu at openjdk.org> wrote:

> Please review this PR and [CSR](https://bugs.openjdk.org/browse/JDK-8312197) which updates the javadoc for the constructor of MessageFormat regarding a `null` locale,
> 
> `MessageFormat` when created with a `null` locale may throw a `NullPointerException` either during the object creation, or later when `format()` is called by the `MessageFormat` object (test file has examples of both). This change updates the specification of MessageFormat to make this apparent. The wording is specifically chosen as 'may throw' since whether an NPE is thrown depends on the subformat used by MessageFormat (see test example of construction with null locale and no exception thrown).
> 
> The test for this change was merged with `Bug6481179.java` into `MessageFormatExceptions.java` (As they both test exceptions). In addition, some other exception testing regarding MessageFormat was added.
> 
> Thanks

src/java.base/share/classes/java/text/MessageFormat.java line 396:

> 394:      * {@code NullPointerException} if {@code locale} is {@code null}
> 395:      * either during the creation of the {@code MessageFormat} object or later
> 396:      * when {@code format()} is called by the constructed {@code MessageFormat} object.

It looks a bit vague as it contains `may`. I think it would be clearer if it explains a bit more, e.g., it throws NPE if any of the subformats require the locale, or along with those lines. Probably the same wording is needed at `format()` and other public methods that use the `locale` field.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/14911#discussion_r1265940997


More information about the i18n-dev mailing list