[foreign] RFR 8219119: Need API to create a null Callback

Sundararajan Athijegannathan sundararajan.athijegannathan at oracle.com
Mon Feb 18 10:23:14 UTC 2019


Throwing NPE from asFunction is direct (& it documents the fact that 
null callback cannot be converted asFunction ). It does not depend on 
some other side effect (of funcClass being null)

Updated to return Callback.ofNull in References.OfFunction and 
DirectSignatureShuffler. (also looked other places of Pointer.ofNull if 
those are for Callbacks - didn't find any other).

Webrev: https://cr.openjdk.java.net/~sundar/8219119/webrev.02/

-Sundar

On 18/02/19, 3:38 PM, Jorn Vernee wrote:
> I see there is a test for asFunction() throwing an NPE. I think the 
> NPE is being triggered from somewhere else already. It looks like this 
> happens by calling
>
>     LibrariesHelper.getCallbackImplClass(funcIntfClass); -> 
> Util.isCallback(c) -> c.isAnnotationPresent(NativeCallback.class);
>
> From CallbackImpl::asFunction. So, maybe the overridden impl is not 
> needed? It might be simpler to just add an isNull() check to the 
> regular implemenation.
>
> Jorn
>
> Jorn Vernee schreef op 2019-02-18 10:30:
>> Hi Sundar,
>>
>> You've changed the implementation of theNullCallback to throw an
>> exception in an overridden asFunction(), but the boxing code in
>> References.OfFunction and DirectSignatureShuffler (others?) would
>> still have to be updated to return theNullCallback explicitly when the
>> address is 0.
>>
>> Jorn
>>
>> Sundararajan Athijegannathan schreef op 2019-02-18 04:52:
>>> Updated: https://cr.openjdk.java.net/~sundar/8219119/webrev.01/
>>>
>>> Thanks
>>> -Sundar
>>>
>>> On 15/02/19, 10:33 PM, Maurizio Cimadamore wrote:
>>>> Looks good - but I think it can be simplified further - there's no 
>>>> need to accept a carrier type in Callback::ofNull.
>>>>
>>>> You can just create a CallbackImpl which throws NPE whenever you 
>>>> try to call 'asFunction'.
>>>>
>>>> Maurizio
>>>>
>>>> On 15/02/2019 17:00, Sundararajan Athijegannathan wrote:
>>>>> Please review.
>>>>>
>>>>> Bug: https://bugs.openjdk.java.net/browse/JDK-8219119
>>>>> Webrev: https://cr.openjdk.java.net/~sundar/8219119/webrev.00/
>>>>>
>>>>> Thanks,
>>>>> -Sundar


More information about the panama-dev mailing list