-
Bug
-
Resolution: Fixed
-
P4
-
8, 11, 15, 17, 18, 19
-
b25
-
generic
-
linux
-
Verified
A DESCRIPTION OF THE PROBLEM :
new File(parent, "/") breaks normalization – creates File with slash at the end
and subsequently it may lead to File with doubled slash in path
new File(parent, "/") will produce the File with slash as an trailing char of the path
If in turn we will try to create yet another child from that File e.g. new File(new File(parent, "/"), "some-file") - it will contain double slash in path. Please see unit-test at Source code section.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See Source code section.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
File path should never contain double slashes, because it always stores normalized path.
ACTUAL -
Double slash in path.
---------- BEGIN SOURCE ----------
public class FileTest {
@Test
public void doubleSlash() {
File parent = new File("//some-dir//");
Assert.assertEquals("/some-dir", parent.getAbsolutePath()); // passed
Assert.assertEquals("/some-dir/some-file", new File(parent, "//some-file//").getAbsolutePath()); // passed
Assert.assertEquals("/some-dir/some-file", new File(parent, "some-file").getAbsolutePath()); // passed
// This assert fails, actual value contains doubled slash: /some-dir//some-file"
Assert.assertEquals("/some-dir/some-file", new File(new File(parent, "/"), "some-file").getAbsolutePath());
}
}
---------- END SOURCE ----------
FREQUENCY : always
new File(parent, "/") breaks normalization – creates File with slash at the end
and subsequently it may lead to File with doubled slash in path
new File(parent, "/") will produce the File with slash as an trailing char of the path
If in turn we will try to create yet another child from that File e.g. new File(new File(parent, "/"), "some-file") - it will contain double slash in path. Please see unit-test at Source code section.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See Source code section.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
File path should never contain double slashes, because it always stores normalized path.
ACTUAL -
Double slash in path.
---------- BEGIN SOURCE ----------
public class FileTest {
@Test
public void doubleSlash() {
File parent = new File("//some-dir//");
Assert.assertEquals("/some-dir", parent.getAbsolutePath()); // passed
Assert.assertEquals("/some-dir/some-file", new File(parent, "//some-file//").getAbsolutePath()); // passed
Assert.assertEquals("/some-dir/some-file", new File(parent, "some-file").getAbsolutePath()); // passed
// This assert fails, actual value contains doubled slash: /some-dir//some-file"
Assert.assertEquals("/some-dir/some-file", new File(new File(parent, "/"), "some-file").getAbsolutePath());
}
}
---------- END SOURCE ----------
FREQUENCY : always
- duplicates
-
JDK-4730835 File constructors handle trailing "/" inconsistently
- Closed