@@ -249,9 +249,22 @@ isnull(obj::JavaMetaClass) = Ptr(obj) == C_NULL
249
249
250
250
macro checknull (expr, msg= " " )
251
251
if expr isa Expr && expr. head == :call
252
- return esc (:( checknull ($ expr, $ msg, $ (expr. args[1 ])) ))
252
+ jnifun = " $(expr. args[1 ]) "
253
+ quote
254
+ local ptr = $ (esc (expr))
255
+ if isnull (ptr) && geterror () === nothing
256
+ throw (JavaCallError (" JavaCall." * $ jnifun* " : " * $ (esc (msg))))
257
+ end
258
+ ptr
259
+ end
253
260
else
254
- return esc (:( checknull ($ expr, $ msg) ))
261
+ quote
262
+ local ptr = $ (esc (expr))
263
+ if isnull (ptr) && geterror () === nothing
264
+ throw (JavaCallError ($ (esc (msg))))
265
+ end
266
+ ptr
267
+ end
255
268
end
256
269
end
257
270
@@ -342,7 +355,7 @@ isarray(juliaclass::String) = endswith(juliaclass, "[]")
342
355
343
356
function jnew (T:: Symbol , argtypes:: Tuple = () , args... )
344
357
assertroottask_or_goodenv () && assertloaded ()
345
- jmethodId = get_method_id (JNI. GetMethodID, Ptr ( metaclass (T)) , " <init>" , Nothing, argtypes)
358
+ jmethodId = get_method_id (JNI. GetMethodID, T , " <init>" , Nothing, argtypes)
346
359
return _jcall (metaclass (T), jmethodId, JavaObject{T}, argtypes, args... ; callmethod= JNI. NewObjectA)
347
360
end
348
361
@@ -366,17 +379,18 @@ function jcall(ref, method::JMethod, args...)
366
379
_jcall (_jcallable (ref), jmethodId, rettype, argtypes, args... )
367
380
end
368
381
369
- function get_method_id (jnifun, ptr , method:: AbstractString , rettype:: Type , argtypes:: Tuple )
382
+ function get_method_id (jnifun:: Function , obj , method:: AbstractString , rettype:: Type , argtypes:: Tuple )
370
383
sig = method_signature (rettype, argtypes... )
371
- @checknull jnifun (ptr, String (method), sig) " $method "
384
+ ptr = Ptr (metaclass (obj))
385
+ @checknull jnifun (ptr, String (method), sig) " Problem getting method id for $obj .$method with signature $sig "
372
386
end
373
387
374
388
function get_method_id (typ:: Type{JavaObject{T}} , method:: AbstractString , rettype:: Type , argtypes:: Tuple ) where T
375
- @checknull get_method_id (JNI. GetStaticMethodID, Ptr ( metaclass (T)) , method, rettype, argtypes)
389
+ get_method_id (JNI. GetStaticMethodID, T , method, rettype, argtypes)
376
390
end
377
391
378
392
function get_method_id (obj:: JavaObject , method:: AbstractString , rettype:: Type , argtypes:: Tuple )
379
- @checknull get_method_id (JNI. GetMethodID, Ptr ( metaclass ( obj)) , method, rettype, argtypes)
393
+ get_method_id (JNI. GetMethodID, obj, method, rettype, argtypes)
380
394
end
381
395
382
396
get_method_id (method:: JMethod ) = @checknull JNI. FromReflectedMethod (method)
0 commit comments