[Java binding] return NULL instead of 0 for jbyteArray methods

This commit is contained in:
Stefan Bratanov 2022-12-20 18:34:29 +02:00
parent c49312af56
commit 00ff3f0a78
2 changed files with 6 additions and 5 deletions

View File

@ -55,7 +55,7 @@ JNIEXPORT void JNICALL Java_ethereum_ckzg4844_CKZG4844JNI_loadTrustedSetup__Ljav
settings = malloc(sizeof(KZGSettings)); settings = malloc(sizeof(KZGSettings));
if (settings == NULL) if (settings == NULL)
{ {
throw_exception(env, "Failed to allocate memory for the trusted setup."); throw_exception(env, "Failed to allocate memory for the Trusted Setup.");
return; return;
} }
@ -95,7 +95,7 @@ JNIEXPORT void JNICALL Java_ethereum_ckzg4844_CKZG4844JNI_loadTrustedSetup___3BJ
settings = malloc(sizeof(KZGSettings)); settings = malloc(sizeof(KZGSettings));
if (settings == NULL) if (settings == NULL)
{ {
throw_exception(env, "Failed to allocate memory for the trusted setup."); throw_exception(env, "Failed to allocate memory for the Trusted Setup.");
return; return;
} }
@ -138,7 +138,7 @@ JNIEXPORT jbyteArray JNICALL Java_ethereum_ckzg4844_CKZG4844JNI_computeAggregate
if (blobs_size != expected_blobs_size) if (blobs_size != expected_blobs_size)
{ {
throw_invalid_size_exception(env, "Invalid blobs size.", blobs_size, expected_blobs_size); throw_invalid_size_exception(env, "Invalid blobs size.", blobs_size, expected_blobs_size);
return 0; return NULL;
} }
jbyte *blobs_native = (*env)->GetByteArrayElements(env, blobs, NULL); jbyte *blobs_native = (*env)->GetByteArrayElements(env, blobs, NULL);
@ -248,7 +248,7 @@ JNIEXPORT jbyteArray JNICALL Java_ethereum_ckzg4844_CKZG4844JNI_blobToKzgCommitm
if (blob_size != BYTES_PER_BLOB) if (blob_size != BYTES_PER_BLOB)
{ {
throw_invalid_size_exception(env, "Invalid blob size.", blob_size, BYTES_PER_BLOB); throw_invalid_size_exception(env, "Invalid blob size.", blob_size, BYTES_PER_BLOB);
return 0; return NULL;
} }
jbyte *blob_native = (*env)->GetByteArrayElements(env, blob, NULL); jbyte *blob_native = (*env)->GetByteArrayElements(env, blob, NULL);

View File

@ -75,7 +75,8 @@ public class TestUtils {
*/ */
public static List<VerifyKzgProofParameters> getVerifyKzgProofTestVectors() { public static List<VerifyKzgProofParameters> getVerifyKzgProofTestVectors() {
final JsonNode jsonNode; final JsonNode jsonNode;
try (InputStream testVectors = readResource("test-vectors/public_verify_kzg_proof.json")) { try (final InputStream testVectors = readResource(
"test-vectors/public_verify_kzg_proof.json")) {
jsonNode = OBJECT_MAPPER.readTree(testVectors); jsonNode = OBJECT_MAPPER.readTree(testVectors);
} catch (final IOException ex) { } catch (final IOException ex) {
throw new UncheckedIOException(ex); throw new UncheckedIOException(ex);