-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect conversion in JNI for non-nullable built-in Blob type #929
Comments
Nullable Blobs also need to be tested for Swift and Dart generators, in case some similar bug is also present there. |
Having a null shared pointer coming from C++ when the type is specified as non-nullable in the IDL is a violation of contract. This specific issue with Blobs only happens because there is no compiler-level mechanism to enforce this contract in C++. The contract is expresses with a The real question is how to handle such contract violations in the conversion code. Current "approach" in JNI is to silently ignore it. If we continue to use this approach, then the proposed fix for the Blobs issue is correct. But do we? What if we throw instead (for Blobs and for classes/interfaces)? @Hsilgos, any preferences? |
The whole |
Updated JNI conversion function for non-nullable Blobs to avoid returning `null` when the C++ function returns a null shared pointer. Having a null shared pointer coming from C++ when the type is specified as non-nullable in the IDL is a violation of contract. The correct fix for this issue would be to change `Blob` representation from `shared_ptr<vector>` to something that cannot be `null`. However, this would be a breaking change, so it has to be done later (#934). For now it's just the small JNI workaround. Resolves: #929 Signed-off-by: Daniel Kamkha <[email protected]>
Created #934 for future |
Updated JNI conversion function for non-nullable Blobs to avoid returning `null` when the C++ function returns a null shared pointer. Having a null shared pointer coming from C++ when the type is specified as non-nullable in the IDL is a violation of contract. The correct fix for this issue would be to change `Blob` representation from `shared_ptr<vector>` to something that cannot be `null`. However, this would be a breaking change, so it has to be done later (#934). For now it's just the small JNI workaround. Resolves: #929 Signed-off-by: Daniel Kamkha <[email protected]>
Updated JNI conversion function for non-nullable Blobs to avoid returning `null` when the C++ function returns a null shared pointer. Having a null shared pointer coming from C++ when the type is specified as non-nullable in the IDL is a violation of contract. The correct fix for this issue would be to change `Blob` representation from `shared_ptr<vector>` to something that cannot be `null`. However, this would be a breaking change, so it has to be done later (#934). For now it's just the small JNI workaround. Resolves: #929 Signed-off-by: Daniel Kamkha <[email protected]>
The built-in Blob type represents std::shared_ptr< std::vector<uint8_t> > in Cpp and byte array in Java.
So Blob can't be nullable in java and must translate to empty array unless it marked @ Nullable (Blob?) type which is std::optional< std::shared_ptr< std::vector<uint8_t> > > in Cpp.
JNI converter converts an empty shared_ptr to null that looks wrong and leads to a runtime exception.
gluecodium/src/main/resources/templates/jni/utils/JniCppConversionUtilsImplementation.mustache
I would suggest converting an empty pointer to an empty java bytearray like in the patch below
The text was updated successfully, but these errors were encountered: