Return error code instead of trying to invoke on null pointer. Seems to fix issue in SoftHSM 2.