From 62b73c09eb2e9392270fcc473dce6a1bcfb550b4 Mon Sep 17 00:00:00 2001 From: Markus Kreusch Date: Tue, 25 Apr 2017 13:08:41 +0200 Subject: [PATCH] Fixed getParent which led to infinite loops under rare circumstances --- src/main/java/org/cryptomator/cryptofs/CryptoPath.java | 4 +++- src/test/java/org/cryptomator/cryptofs/CryptoPathTest.java | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/cryptomator/cryptofs/CryptoPath.java b/src/main/java/org/cryptomator/cryptofs/CryptoPath.java index 51ca7f77..6969671b 100644 --- a/src/main/java/org/cryptomator/cryptofs/CryptoPath.java +++ b/src/main/java/org/cryptomator/cryptofs/CryptoPath.java @@ -94,8 +94,10 @@ public CryptoPath getParent() { if (elementCount > 1) { List elems = elements.subList(0, elementCount - 1); return copyWithElements(elems); - } else { + } else if (elementCount == 1) { return getRoot(); + } else { + return null; } } diff --git a/src/test/java/org/cryptomator/cryptofs/CryptoPathTest.java b/src/test/java/org/cryptomator/cryptofs/CryptoPathTest.java index c6cd3c2e..c2e12b15 100644 --- a/src/test/java/org/cryptomator/cryptofs/CryptoPathTest.java +++ b/src/test/java/org/cryptomator/cryptofs/CryptoPathTest.java @@ -119,11 +119,13 @@ public void testGetParent() { Path p1 = path("/foo"); Path p2 = path("/foo/bar"); Path p3 = path("foo"); + Path p4 = path("/"); Assert.assertEquals(p1, p2.getParent()); Assert.assertEquals(rootPath, p1.getParent()); Assert.assertNull(emptyPath.getParent()); Assert.assertNull(p3.getParent()); + Assert.assertNull(p4.getParent()); } @Test