From e8bde375ccc80ae6638187d0ba129e20a612f3c9 Mon Sep 17 00:00:00 2001 From: David Gault Date: Tue, 1 Aug 2017 13:20:03 +0100 Subject: [PATCH 01/11] Add null parent unit test --- src/test/java/loci/common/utests/LocationTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/test/java/loci/common/utests/LocationTest.java b/src/test/java/loci/common/utests/LocationTest.java index dc6c5371..f564eacf 100644 --- a/src/test/java/loci/common/utests/LocationTest.java +++ b/src/test/java/loci/common/utests/LocationTest.java @@ -271,6 +271,12 @@ public void testParentRoot() { assertEquals(file.getName(), null, file.getParent()); } } + + @Test + public void testParentNull() { + Location nullParent = new Location("nullParentFile", null); + assertEquals(nullParent.getName(), null, nullParent.getParentFile()); + } @Test public void testIsDirectory() { From 438ccd4254385e8feeb82637412e47556fc2e249 Mon Sep 17 00:00:00 2001 From: David Gault Date: Tue, 1 Aug 2017 13:31:28 +0100 Subject: [PATCH 02/11] Correct parent child parameters --- src/test/java/loci/common/utests/LocationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/loci/common/utests/LocationTest.java b/src/test/java/loci/common/utests/LocationTest.java index f564eacf..9deb51ca 100644 --- a/src/test/java/loci/common/utests/LocationTest.java +++ b/src/test/java/loci/common/utests/LocationTest.java @@ -274,7 +274,7 @@ public void testParentRoot() { @Test public void testParentNull() { - Location nullParent = new Location("nullParentFile", null); + Location nullParent = new Location(null, "nullParentFile"); assertEquals(nullParent.getName(), null, nullParent.getParentFile()); } From f5bb733adb2dde267939521d4d96683a4f73c50c Mon Sep 17 00:00:00 2001 From: David Gault Date: Tue, 1 Aug 2017 16:07:53 +0100 Subject: [PATCH 03/11] Location test: null parent for String and Location --- src/test/java/loci/common/utests/LocationTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test/java/loci/common/utests/LocationTest.java b/src/test/java/loci/common/utests/LocationTest.java index 9deb51ca..002cade3 100644 --- a/src/test/java/loci/common/utests/LocationTest.java +++ b/src/test/java/loci/common/utests/LocationTest.java @@ -274,7 +274,9 @@ public void testParentRoot() { @Test public void testParentNull() { - Location nullParent = new Location(null, "nullParentFile"); + Location nullParent = new Location((String) null, "nullParentFile"); + assertEquals(nullParent.getName(), null, nullParent.getParentFile()); + nullParent = new Location((Location) null, "nullParentFile"); assertEquals(nullParent.getName(), null, nullParent.getParentFile()); } From 0cc6cbf288a4cd21d4d416b76a54e33799e6aeda Mon Sep 17 00:00:00 2001 From: David Gault Date: Wed, 9 Aug 2017 16:11:10 +0100 Subject: [PATCH 04/11] LocationTest: Prevent mismatched nulls --- src/test/java/loci/common/utests/LocationTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/loci/common/utests/LocationTest.java b/src/test/java/loci/common/utests/LocationTest.java index 002cade3..aadd715f 100644 --- a/src/test/java/loci/common/utests/LocationTest.java +++ b/src/test/java/loci/common/utests/LocationTest.java @@ -275,9 +275,9 @@ public void testParentRoot() { @Test public void testParentNull() { Location nullParent = new Location((String) null, "nullParentFile"); - assertEquals(nullParent.getName(), null, nullParent.getParentFile()); + assertEquals(nullParent.getName(), String.valueOf("null"), nullParent.getParentFile()); nullParent = new Location((Location) null, "nullParentFile"); - assertEquals(nullParent.getName(), null, nullParent.getParentFile()); + assertEquals(nullParent.getName(), String.valueOf("null"), nullParent.getParentFile()); } @Test From 0747b3f88dae7a2cb708f7785199019a4d5087d9 Mon Sep 17 00:00:00 2001 From: David Gault Date: Wed, 9 Aug 2017 19:50:11 +0100 Subject: [PATCH 05/11] Location test: Use assertNull --- src/test/java/loci/common/utests/LocationTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/java/loci/common/utests/LocationTest.java b/src/test/java/loci/common/utests/LocationTest.java index aadd715f..9151910d 100644 --- a/src/test/java/loci/common/utests/LocationTest.java +++ b/src/test/java/loci/common/utests/LocationTest.java @@ -33,6 +33,7 @@ package loci.common.utests; import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertNull; import java.io.File; import java.io.IOException; @@ -275,9 +276,9 @@ public void testParentRoot() { @Test public void testParentNull() { Location nullParent = new Location((String) null, "nullParentFile"); - assertEquals(nullParent.getName(), String.valueOf("null"), nullParent.getParentFile()); + assertNull(nullParent.getParentFile()); nullParent = new Location((Location) null, "nullParentFile"); - assertEquals(nullParent.getName(), String.valueOf("null"), nullParent.getParentFile()); + assertNull(nullParent.getParentFile()); } @Test From 6301e60d01a0f0587578f52ae3b57e0585ab7ebf Mon Sep 17 00:00:00 2001 From: Sebastien Besson Date: Mon, 14 Jan 2019 15:00:33 +0000 Subject: [PATCH 06/11] Remove whitespace --- src/test/java/loci/common/utests/LocationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/loci/common/utests/LocationTest.java b/src/test/java/loci/common/utests/LocationTest.java index 9151910d..b9fd4095 100644 --- a/src/test/java/loci/common/utests/LocationTest.java +++ b/src/test/java/loci/common/utests/LocationTest.java @@ -272,7 +272,7 @@ public void testParentRoot() { assertEquals(file.getName(), null, file.getParent()); } } - + @Test public void testParentNull() { Location nullParent = new Location((String) null, "nullParentFile"); From d1d980b2fa38d75d6c3d46c6e976d1f2057cc9cf Mon Sep 17 00:00:00 2001 From: David Gault Date: Tue, 1 Aug 2017 11:50:41 +0100 Subject: [PATCH 07/11] getParent returns null if does not exist --- src/main/java/loci/common/Location.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/loci/common/Location.java b/src/main/java/loci/common/Location.java index a5fc14e2..b358b3e1 100644 --- a/src/main/java/loci/common/Location.java +++ b/src/main/java/loci/common/Location.java @@ -870,7 +870,9 @@ public String getParent() { * @see java.io.File#getParentFile() */ public Location getParentFile() { - return new Location(getParent()); + String parent = this.getParent(); + if (parent == null) return null; + return new Location(parent); } /** From c4e54a07e5584463b876483e2465119134978163 Mon Sep 17 00:00:00 2001 From: David Gault Date: Wed, 9 Aug 2017 19:49:53 +0100 Subject: [PATCH 08/11] Handle null pointer in constructor --- src/main/java/loci/common/Location.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/loci/common/Location.java b/src/main/java/loci/common/Location.java index b358b3e1..9537ce01 100644 --- a/src/main/java/loci/common/Location.java +++ b/src/main/java/loci/common/Location.java @@ -246,7 +246,7 @@ public Location(String parent, String child) { * @see #Location(String, String) */ public Location(Location parent, String child) { - this(parent.getAbsolutePath(), child); + this(parent == null ? (String) null : parent.getAbsolutePath(), child); } // -- Location API methods -- From d316cdf50eceb757b0da3cca353d157278602dca Mon Sep 17 00:00:00 2001 From: Sebastien Besson Date: Thu, 10 Aug 2017 12:22:20 +0100 Subject: [PATCH 09/11] Copy File Javadoc and fix see also --- src/main/java/loci/common/Location.java | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main/java/loci/common/Location.java b/src/main/java/loci/common/Location.java index 9537ce01..70af57b4 100644 --- a/src/main/java/loci/common/Location.java +++ b/src/main/java/loci/common/Location.java @@ -56,8 +56,8 @@ import com.google.common.collect.MapMaker; /** - * Pseudo-extension of java.io.File that supports reading over HTTP (among - * other things). + * Pseudo-extension of {@link java.io.File} that supports reading over HTTP + * (among other things). * It is strongly recommended to use this instead of java.io.File. */ public class Location { @@ -842,9 +842,13 @@ public String getName() { } /** - * Returns the name of this file's parent directory, i.e. the path name prefix - * and every name in the path name sequence except for the last. - * If this file does not have a parent directory, then null is returned. + * Returns the pathname string of this abstract pathname's parent, or null if + * this pathname does not have a parent directory. + * + * The parent of an abstract pathname consists of the pathname's prefix, if + * any, and each name in the pathname's name sequence except for the last. + * If the name sequence is empty then the pathname does not name a parent + * directory. * * @return see above * @see java.io.File#getParent() @@ -864,9 +868,16 @@ public String getParent() { } /** - * Returns this file's parent directory. + * Returns the abstract pathname of this abstract pathname's parent, or null + * if this pathname does not name a parent directory. + * + * The parent of an abstract pathname consists of the pathname's prefix, if + * any, and each name in the pathname's name sequence except for the last. + * If the name sequence is empty then the pathname does not name a parent + * directory. * * @return the Location representing {@link #getParent()} + * * @see java.io.File#getParentFile() */ public Location getParentFile() { From 6d5d0630aeccaa90ce1aef66fdc5c4d622192b1d Mon Sep 17 00:00:00 2001 From: Sebastien Besson Date: Thu, 10 Aug 2017 12:30:07 +0100 Subject: [PATCH 10/11] Remove whitespace --- src/main/java/loci/common/Location.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/loci/common/Location.java b/src/main/java/loci/common/Location.java index 70af57b4..e30e0243 100644 --- a/src/main/java/loci/common/Location.java +++ b/src/main/java/loci/common/Location.java @@ -57,7 +57,7 @@ /** * Pseudo-extension of {@link java.io.File} that supports reading over HTTP - * (among other things). + * (among other things). * It is strongly recommended to use this instead of java.io.File. */ public class Location { From c042027e577087270356aa17a224c0158f4a127e Mon Sep 17 00:00:00 2001 From: Sebastien Besson Date: Mon, 14 Jan 2019 15:13:31 +0000 Subject: [PATCH 11/11] Fix return type to match java.io.File --- src/main/java/loci/common/Location.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/loci/common/Location.java b/src/main/java/loci/common/Location.java index e30e0243..3d552dee 100644 --- a/src/main/java/loci/common/Location.java +++ b/src/main/java/loci/common/Location.java @@ -876,8 +876,8 @@ public String getParent() { * If the name sequence is empty then the pathname does not name a parent * directory. * - * @return the Location representing {@link #getParent()} - * + * @return The abstract pathname of the parent directory named by this + * abstract pathname, or null if this pathname does not name a parent * @see java.io.File#getParentFile() */ public Location getParentFile() {