RFR: 8210765: Remove finalize method in CStrike.java [v2]

Prasanta Sadhukhan psadhukhan at openjdk.org
Fri Aug 1 03:20:55 UTC 2025


On Thu, 31 Jul 2025 19:47:29 GMT, Phil Race <prr at openjdk.org> wrote:

>> src/java.desktop/macosx/classes/sun/font/CStrike.java line 99:
>> 
>>> 97: 
>>> 98:     public long getNativeStrikePtr() {
>>> 99:         return nativeStrikePtr;
>> 
>> Any reason this check was removed?
>> I see that initNativeStrikePtr will call createNativeStrikePtr which does this where there is no null check and it just returns what it gets so shouldn't we check it here?
>> 
>> 
>> awtStrike = [AWTStrike awtStrikeForFont:awtFont tx:glyphTx invDevTx:invDevTx style:style aaStyle:aaStyle]; // autoreleased
>> 
>>     if (awtStrike)
>>     {
>>         CFRetain(awtStrike); // GC
>>     }
>> 
>> JNI_COCOA_EXIT(env);
>>     return ptr_to_jlong(awtStrike);
>
> And if it is 0, what would you do ?
> Previously 0 meant it hadn't yet been initialized. Now it is always initialized.
> 
> You'd need to return it anyway even it was zero.

Then I guess whoever is using the `nativeStrikePtr` should account for that it can receive null or 0..
I haven't seen all cases but one case I saw `getFontMetrics `calls `getFontMetrics(getNativeStrikePtr())`
and there it does this where it dereference `awtStrikePtr`...Shouldn't it cause SIGSEGV if it ever becomes 0?


JNIEXPORT jobject JNICALL
Java_sun_font_CStrike_getFontMetrics
    (JNIEnv *env, jclass clazz, jlong awtStrikePtr)
{
    jobject metrics = NULL;

JNI_COCOA_ENTER(env);
    AWT_FONT_CLEANUP_SETUP;

    AWTFont *awtfont = ((AWTStrike *)jlong_to_ptr(awtStrikePtr))->fAWTFont;

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

PR Review Comment: https://git.openjdk.org/jdk/pull/26397#discussion_r2246796256


More information about the client-libs-dev mailing list