diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSClient.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSClient.java index 2f006931577..106ef282c5b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSClient.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DFSClient.java @@ -2153,6 +2153,10 @@ public class DFSClient implements java.io.Closeable, RemotePeerFactory, String fromSnapshot, String toSnapshot) throws IOException { checkOpen(); try (TraceScope ignored = tracer.newScope("getSnapshotDiffReport")) { + Preconditions.checkArgument(fromSnapshot != null, + "null fromSnapshot"); + Preconditions.checkArgument(toSnapshot != null, + "null toSnapshot"); return namenode .getSnapshotDiffReport(snapshotDir, fromSnapshot, toSnapshot); } catch (RemoteException re) { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/DirectorySnapshottableFeature.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/DirectorySnapshottableFeature.java index d3083cf222a..15aa22a0af2 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/DirectorySnapshottableFeature.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/DirectorySnapshottableFeature.java @@ -277,7 +277,7 @@ public class DirectorySnapshottableFeature extends DirectoryWithSnapshotFeature Snapshot fromSnapshot = getSnapshotByName(snapshotRootDir, from); Snapshot toSnapshot = getSnapshotByName(snapshotRootDir, to); // if the start point is equal to the end point, return null - if (from.equals(to)) { + if (from != null && from.equals(to)) { return null; } SnapshotDiffInfo diffs = new SnapshotDiffInfo(snapshotRootDir, diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotDiffReport.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotDiffReport.java index 4625988fdd2..18ec3c581d5 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotDiffReport.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotDiffReport.java @@ -230,6 +230,12 @@ public class TestSnapshotDiffReport { LOG.info(report.toString()); assertEquals(0, report.getDiffList().size()); + try { + report = hdfs.getSnapshotDiffReport(subsubsub1, null, "s2"); + fail("Expect exception when providing null fromSnapshot "); + } catch (IllegalArgumentException e) { + GenericTestUtils.assertExceptionContains("null fromSnapshot", e); + } report = hdfs.getSnapshotDiffReport(subsubsub1, "s0", "s2"); LOG.info(report.toString()); assertEquals(0, report.getDiffList().size()); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHDFS.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHDFS.java index a7ae90c9ec2..d27646e3587 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHDFS.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHDFS.java @@ -743,6 +743,12 @@ public class TestWebHDFS { Assert.assertTrue(diffReport.getDiffList().contains(entry3)); Assert.assertTrue(diffReport.getDiffList().contains(entry4)); Assert.assertEquals(diffReport.getDiffList().size(), 5); + + // Test with fromSnapshot and toSnapshot as null. + diffReport = webHdfs.getSnapshotDiffReport(foo, null, "s2"); + Assert.assertEquals(diffReport.getDiffList().size(), 0); + diffReport = webHdfs.getSnapshotDiffReport(foo, "s1", null); + Assert.assertEquals(diffReport.getDiffList().size(), 5); } finally { if (cluster != null) { cluster.shutdown();