[RocksJava] Sigsegv fix for MergerOperatorByName

This commit is contained in:
fyrz 2014-11-15 12:37:51 +01:00
parent 274ba62707
commit a280af2a57
6 changed files with 67 additions and 10 deletions

View File

@ -56,6 +56,7 @@ JAVA_TESTS = org.rocksdb.test.BackupableDBOptionsTest\
org.rocksdb.test.ComparatorTest\
org.rocksdb.test.DBOptionsTest\
org.rocksdb.test.DirectComparatorTest\
org.rocksdb.test.EnvironmentTest\
org.rocksdb.test.FilterTest\
org.rocksdb.test.FlushTest\
org.rocksdb.test.InfoLogLevelTest\
@ -70,6 +71,7 @@ JAVA_TESTS = org.rocksdb.test.BackupableDBOptionsTest\
org.rocksdb.test.RocksDBTest\
org.rocksdb.test.RocksEnvTest\
org.rocksdb.test.RocksIteratorTest\
org.rocksdb.test.SizeUnitTest\
org.rocksdb.test.SnapshotTest\
org.rocksdb.test.StatisticsCollectorTest\
org.rocksdb.test.WriteBatchHandlerTest\
@ -130,7 +132,7 @@ resolve_test_deps:
test -s "$(JAVA_ASSERTJ_JAR)" || curl -k -L -o "$(JAVA_ASSERTJ_JAR)" http://central.maven.org/maven2/org/assertj/assertj-core/1.7.0/assertj-core-1.7.0.jar
test: java resolve_test_deps
java -ea -Djava.library.path=.:../ -cp "$(JAVA_TESTCLASSPATH)" org.rocksdb.test.RocksJunitRunner $(JAVA_TESTS)
java -ea -Xcheck:jni -Djava.library.path=.:../ -cp "$(JAVA_TESTCLASSPATH)" org.rocksdb.test.RocksJunitRunner $(JAVA_TESTS)
db_bench: java
javac org/rocksdb/benchmark/*.java

View File

@ -127,6 +127,8 @@ public class ColumnFamilyOptions extends RocksObject
@Override
public ColumnFamilyOptions setMergeOperatorName(String name) {
assert (isInitialized());
assert (name != null);
setMergeOperatorName(nativeHandle_, name);
return this;
}

View File

@ -165,6 +165,8 @@ public class Options extends RocksObject
@Override
public Options setMergeOperatorName(String name) {
assert (isInitialized());
assert (name != null);
setMergeOperatorName(nativeHandle_, name);
return this;
}

View File

@ -8,6 +8,7 @@ package org.rocksdb.test;
import java.util.List;
import java.util.ArrayList;
import org.junit.Assert;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
@ -252,4 +253,50 @@ public class MergeTest {
}
}
}
@Test
public void emptyStringInSetMergeOperatorByName() {
Options opt = null;
ColumnFamilyOptions cOpt = null;
try {
opt = new Options();
cOpt = new ColumnFamilyOptions();
opt.setMergeOperatorName("");
cOpt.setMergeOperatorName("");
} finally {
if (opt != null) {
opt.dispose();
}
if (cOpt != null) {
cOpt.dispose();
}
}
}
@Test(expected = AssertionError.class)
public void nullStringInSetMergeOperatorByNameOptions() {
Options opt = null;
try {
opt = new Options();
opt.setMergeOperatorName(null);
} finally {
if (opt != null) {
opt.dispose();
}
}
}
@Test(expected = AssertionError.class)
public void
nullStringInSetMergeOperatorByNameColumnFamilyOptions() {
ColumnFamilyOptions opt = null;
try {
opt = new ColumnFamilyOptions();
opt.setMergeOperatorName(null);
} finally {
if (opt != null) {
opt.dispose();
}
}
}
}

View File

@ -118,7 +118,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<argLine>${argLine}</argLine>
<argLine>${argLine} -Xcheck:jni</argLine>
</configuration>
</plugin>
<plugin>

View File

@ -146,10 +146,12 @@ void Java_org_rocksdb_Options_setComparatorHandle__JJ(
* Signature: (JJjava/lang/String)V
*/
void Java_org_rocksdb_Options_setMergeOperatorName(
JNIEnv* env, jobject jobj, jlong jhandle, jstring name) {
const char* op_name = env->GetStringUTFChars(name, 0);
reinterpret_cast<rocksdb::Options*>(jhandle)->merge_operator =
rocksdb::MergeOperators::CreateFromStringId(op_name);
JNIEnv* env, jobject jobj, jlong jhandle, jstring jop_name) {
auto options = reinterpret_cast<rocksdb::Options*>(jhandle);
const char* op_name = env->GetStringUTFChars(jop_name, 0);
options->merge_operator = rocksdb::MergeOperators::CreateFromStringId(
op_name);
env->ReleaseStringUTFChars(jop_name, op_name);
}
/*
@ -1884,10 +1886,12 @@ void Java_org_rocksdb_ColumnFamilyOptions_setComparatorHandle__JI(
* Signature: (JJjava/lang/String)V
*/
void Java_org_rocksdb_ColumnFamilyOptions_setMergeOperatorName(
JNIEnv* env, jobject jobj, jlong jhandle, jstring name) {
const char* op_name = env->GetStringUTFChars(name, 0);
reinterpret_cast<rocksdb::ColumnFamilyOptions*>(jhandle)->merge_operator =
rocksdb::MergeOperators::CreateFromStringId(op_name);
JNIEnv* env, jobject jobj, jlong jhandle, jstring jop_name) {
auto options = reinterpret_cast<rocksdb::ColumnFamilyOptions*>(jhandle);
const char* op_name = env->GetStringUTFChars(jop_name, 0);
options->merge_operator = rocksdb::MergeOperators::CreateFromStringId(
op_name);
env->ReleaseStringUTFChars(jop_name, op_name);
}
/*