diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HTable.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HTable.java index 377988d74c7..b7b15065b33 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HTable.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HTable.java @@ -921,7 +921,9 @@ public class HTable implements HTableInterface { if (row == null) { npe = new NullPointerException("row is null"); } else if (family == null) { - npe = new NullPointerException("column is null"); + npe = new NullPointerException("family is null"); + } else if (qualifier == null) { + npe = new NullPointerException("qualifier is null"); } if (npe != null) { throw new IOException( diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Increment.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Increment.java index 0a8033c0302..a21bd48e4a7 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Increment.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Increment.java @@ -78,6 +78,9 @@ public class Increment implements Row { * @param rowLock previously acquired row lock, or null */ public Increment(byte [] row, RowLock rowLock) { + if (row == null) { + throw new IllegalArgumentException("Cannot increment a null row"); + } this.row = row; if(rowLock != null) { this.lockId = rowLock.getLockId(); @@ -95,6 +98,12 @@ public class Increment implements Row { * @return the Increment object */ public Increment addColumn(byte [] family, byte [] qualifier, long amount) { + if (family == null) { + throw new IllegalArgumentException("family cannot be null"); + } + if (qualifier == null) { + throw new IllegalArgumentException("qualifier cannot be null"); + } NavigableMap set = familyMap.get(family); if(set == null) { set = new TreeMap(Bytes.BYTES_COMPARATOR); diff --git a/hbase-server/src/main/ruby/hbase/table.rb b/hbase-server/src/main/ruby/hbase/table.rb index a4d1fe94506..bcbb3ae69a0 100644 --- a/hbase-server/src/main/ruby/hbase/table.rb +++ b/hbase-server/src/main/ruby/hbase/table.rb @@ -154,6 +154,9 @@ EOF def _incr_internal(row, column, value = nil) value ||= 1 family, qualifier = parse_column_name(column) + if qualifier.nil? + raise ArgumentError, "Failed to provide both column family and column qualifier for incr" + end @table.incrementColumnValue(row.to_s.to_java_bytes, family, qualifier, value) end diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java index 2f688efd717..23852121d2e 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java @@ -4295,6 +4295,59 @@ public class TestFromClientSide { } } + @Test + public void testIncrementInvalidArguments() throws Exception { + LOG.info("Starting testIncrementInvalidArguments"); + final byte[] TABLENAME = Bytes.toBytes("testIncrementInvalidArguments"); + HTable ht = TEST_UTIL.createTable(TABLENAME, FAMILY); + final byte[] COLUMN = Bytes.toBytes("column"); + try { + // try null row + ht.incrementColumnValue(null, FAMILY, COLUMN, 5); + fail("Should have thrown IOException"); + } catch (IOException iox) { + // success + } + try { + // try null family + ht.incrementColumnValue(ROW, null, COLUMN, 5); + fail("Should have thrown IOException"); + } catch (IOException iox) { + // success + } + try { + // try null qualifier + ht.incrementColumnValue(ROW, FAMILY, null, 5); + fail("Should have thrown IOException"); + } catch (IOException iox) { + // success + } + // try null row + try { + Increment incNoRow = new Increment(null); + incNoRow.addColumn(FAMILY, COLUMN, 5); + fail("Should have thrown IllegalArgumentException"); + } catch (IllegalArgumentException iax) { + // success + } + // try null family + try { + Increment incNoFamily = new Increment(ROW); + incNoFamily.addColumn(null, COLUMN, 5); + fail("Should have thrown IllegalArgumentException"); + } catch (IllegalArgumentException iax) { + // success + } + // try null qualifier + try { + Increment incNoQualifier = new Increment(ROW); + incNoQualifier.addColumn(FAMILY, null, 5); + fail("Should have thrown IllegalArgumentException"); + } catch (IllegalArgumentException iax) { + // success + } + } + @Test