<i18n dev> RFR: 8341445: DecimalFormatSymbols can throw NPE for equals()

Chen Liang liach at openjdk.org
Thu Oct 3 00:51:38 UTC 2024


On Wed, 2 Oct 2024 23:16:32 GMT, Justin Lu <jlu at openjdk.org> wrote:

> Please review this PR which improves the safety of equality checking for DecimalFormatSymbols.
> 
> DecimalFormatSymbols via its setters, allows certain instance variables to be set as null. (Note that some variables are allowed to be null, and others are not.) However, non null safe comparisons are used for all variables during the equality check. This can lead to an unexpected NPE when `DecimalFormatSymbols.equals()` is invoked.
> 
> The nullable variables in question should be equality checked via the static `Object.equals()`. An associated regression test is added to confirm the change.

Should we add an explicit whitelist of methods allowed to throw NPE, so that if we add new getter/setters to DFS, we can avoid this nasty null problem for the future? This whitelist will be validated by tests for sure.

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

PR Comment: https://git.openjdk.org/jdk/pull/21315#issuecomment-2390288579


More information about the i18n-dev mailing list