@ -121,6 +121,9 @@ jint Java_org_rocksdb_RocksDB_get___3BI_3BI(
JNIEnv * env , jobject jdb ,
JNIEnv * env , jobject jdb ,
jbyteArray jkey , jint jkey_len ,
jbyteArray jkey , jint jkey_len ,
jbyteArray jvalue , jint jvalue_len ) {
jbyteArray jvalue , jint jvalue_len ) {
static const int kNotFound = - 1 ;
static const int kStatusError = - 2 ;
rocksdb : : DB * db = rocksdb : : RocksDBJni : : getHandle ( env , jdb ) ;
rocksdb : : DB * db = rocksdb : : RocksDBJni : : getHandle ( env , jdb ) ;
jboolean isCopy ;
jboolean isCopy ;
@ -142,24 +145,29 @@ jint Java_org_rocksdb_RocksDB_get___3BI_3BI(
if ( s . IsNotFound ( ) ) {
if ( s . IsNotFound ( ) ) {
env - > ReleaseByteArrayElements ( jvalue , value , JNI_ABORT ) ;
env - > ReleaseByteArrayElements ( jvalue , value , JNI_ABORT ) ;
return - 1 ;
return kNotFound ;
} else if ( s . ok ( ) ) {
} else if ( ! s . ok ( ) ) {
int cvalue_len = static_cast < int > ( cvalue . size ( ) ) ;
// Here since we are throwing a Java exception from c++ side.
int length = cvalue_len ;
// As a result, c++ does not know calling this function will in fact
// currently we prevent overflowing.
// throwing an exception. As a result, the execution flow will
if ( length > jvalue_len ) {
// not stop here, and codes after this throw will still be
length = jvalue_len ;
// executed.
}
rocksdb : : RocksDBExceptionJni : : ThrowNew ( env , s ) ;
memcpy ( value , cvalue . c_str ( ) , length ) ;
env - > ReleaseByteArrayElements ( jvalue , value , JNI_COMMIT ) ;
// Return a dummy const value to avoid compilation error, although
if ( cvalue_len > length ) {
// java side might not have a chance to get the return value :)
return static_cast < jint > ( cvalue . size ( ) ) ;
return kStatusError ;
}
return length ;
}
}
rocksdb : : RocksDBExceptionJni : : ThrowNew ( env , s ) ;
return - 1 ;
int cvalue_len = static_cast < int > ( cvalue . size ( ) ) ;
int length = std : : min ( jvalue_len , cvalue_len ) ;
memcpy ( value , cvalue . c_str ( ) , length ) ;
env - > ReleaseByteArrayElements ( jvalue , value , JNI_COMMIT ) ;
if ( cvalue_len > length ) {
return static_cast < jint > ( cvalue_len ) ;
}
return length ;
}
}
/*
/*