HBASE-8794 DependentColumnFilter.toString() throws NullPointerException (Stefan Seelmann)

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1498536 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
larsh 2013-07-01 16:01:45 +00:00
parent a7655cccf2
commit dfc29dcabf
2 changed files with 29 additions and 1 deletions

View File

@ -285,6 +285,6 @@ public class DependentColumnFilter extends CompareFilter {
Bytes.toStringBinary(this.columnQualifier),
this.dropDependentColumn,
this.compareOp.name(),
Bytes.toStringBinary(this.comparator.getValue()));
this.comparator != null ? Bytes.toStringBinary(this.comparator.getValue()) : "null");
}
}

View File

@ -39,6 +39,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.experimental.categories.Category;
@ -247,5 +248,32 @@ public class TestDependentColumnFilter {
assertEquals("check cell retention", 2, accepted.size());
}
/**
* Test for HBASE-8794. Avoid NullPointerException in DependentColumnFilter.toString().
*/
@Test
public void testToStringWithNullComparator() {
// Test constructor that implicitly sets a null comparator
Filter filter = new DependentColumnFilter(FAMILIES[0], QUALIFIER);
assertNotNull(filter.toString());
assertTrue("check string contains 'null' as compatator is null",
filter.toString().contains("null"));
// Test constructor with explicit null comparator
filter = new DependentColumnFilter(FAMILIES[0], QUALIFIER, true, CompareOp.EQUAL, null);
assertNotNull(filter.toString());
assertTrue("check string contains 'null' as compatator is null",
filter.toString().contains("null"));
}
@Test
public void testToStringWithNonNullComparator() {
Filter filter =
new DependentColumnFilter(FAMILIES[0], QUALIFIER, true, CompareOp.EQUAL,
new BinaryComparator(MATCH_VAL));
assertNotNull(filter.toString());
assertTrue("check string contains comparator value", filter.toString().contains("match"));
}
}