diff --git a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/RegionsResource.java b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/RegionsResource.java index c3eed6a2eec..6d6293fb164 100644 --- a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/RegionsResource.java +++ b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/RegionsResource.java @@ -75,6 +75,9 @@ public class RegionsResource extends ResourceBase { servlet.getMetrics().incrementRequests(1); try { TableName tableName = TableName.valueOf(tableResource.getName()); + if (!tableResource.exists()) { + throw new TableNotFoundException(tableName); + } TableInfoModel model = new TableInfoModel(tableName.getNameAsString()); List locs; diff --git a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestTableResource.java b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestTableResource.java index 7cbc6318b75..b069693b99f 100644 --- a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestTableResource.java +++ b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestTableResource.java @@ -261,5 +261,14 @@ public class TestTableResource { checkTableInfo(model); } + @Test + public void testTableNotFound() throws IOException { + String notExistTable = "notexist"; + Response response1 = client.get("/" + notExistTable + "/schema", Constants.MIMETYPE_JSON); + assertEquals(404, response1.getCode()); + Response response2 = client.get("/" + notExistTable + "/regions", Constants.MIMETYPE_XML); + assertEquals(404, response2.getCode()); + } + }