RFR: 8328874: Class::forName0 should validate the class name length early [v5]
Guanqiang Han
ghan at openjdk.org
Thu Aug 21 02:03:54 UTC 2025
On Wed, 20 Aug 2025 21:34:29 GMT, ExE Boss <duke at openjdk.org> wrote:
>> Guanqiang Han has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Update Class.java
>>
>> updates the class name length validation logic on the Java side
>
> src/java.base/share/classes/java/lang/Class.java line 4160:
>
>> 4158: // Checks whether the class name exceeds the maximum allowed length.
>> 4159: private static boolean classNameLengthIsValid(String name) {
>> 4160: Objects.requireNonNull(name);
>
> This is not needed as the `name.length()` call already performs an implicit `null` check.
hi @ExE-Boss ,thanks for your comment regarding the Objects.requireNonNull(name) call. I understand that name.length() triggers an implicit null check, which could make the explicit check seem redundant.
However, I wonder if there is a subtle difference worth considering here: the implicit null check relies on the system exception (signal) mechanism and subsequent JVM handling, which does have some overhead. In addition, as i know, C2 decides whether to use implicit null checks after performing statistical analysis. For this kind of core library, should we assume that null is a low-probability event?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/26802#discussion_r2289682197
More information about the core-libs-dev
mailing list