-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update relativize method for java 9 #175
Conversation
I noticed the io spec was failing on my mac on jdk9 (but passing on travis, which was running jdk 8). The relativize method arguably didn't work correctly on pre jdk 9 jres (at least on osx). For example, I ran the following in the console: scala> import java.nio.file._ scala> val base = Paths.get("/foo/bar/..") val base = Paths.get("/foo/bar/..") base: java.nio.file.Path = /foo/bar/.. scala> val file = Paths.get("/foo/buzz") val file = Paths.get("/foo/buzz") file: java.nio.file.Path = /foo/buzz scala> val relative = base.relativize(file) val relative = base.relativize(file) ^ relative: java.nio.file.Path = ../../buzz scala> base.resolve(relative).normalize base.resolve(relative).normalize ^ res5: java.nio.file.Path = /buzz This result is certainly not what I would expect. The fix is very easy, just always normalize the paths (which is not very expensive, especially compared to any file system operation).
@@ -22,7 +22,7 @@ class IOSpec extends FlatSpec with Matchers { | |||
val relativeRootDir = new File(nestedDir, "..") | |||
|
|||
IO.relativize(rootDir.toFile, nestedFile).map(file) shouldBe Some(file("meh.file")) | |||
IO.relativize(relativeRootDir, nestedFile).map(file) shouldBe Some(file("../../meh.file")) | |||
IO.relativize(relativeRootDir, nestedFile).map(file) shouldBe Some(file("meh.file")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this changes the behavior from previous releases, but this looks better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. On jdk 9, this is what is returned even if normalize is not called in IO.relativize (which is how I found the issue in the first place). I'd be surprised if anyone was relying on the previous behavior.
A validation involving this pull request is in progress... |
Dbuild doesn't work with sbt 1.2.0, so the test result is nonsensical. |
I noticed the io spec was failing on my mac on jdk9 (but passing on
travis, which was running jdk 8). The relativize method arguably didn't
work correctly on pre jdk 9 jres (at least on osx). For example, I ran
the following in the console:
scala> import java.nio.file._
scala> val base = Paths.get("/foo/bar/..")
val base = Paths.get("/foo/bar/..")
base: java.nio.file.Path = /foo/bar/..
scala> val file = Paths.get("/foo/buzz")
val file = Paths.get("/foo/buzz")
file: java.nio.file.Path = /foo/buzz
scala> val relative = base.relativize(file)
val relative = base.relativize(file)
^
relative: java.nio.file.Path = ../../buzz
scala> base.resolve(relative).normalize
base.resolve(relative).normalize
^
res5: java.nio.file.Path = /buzz
This result is certainly not what I would expect. The fix is very easy,
just always normalize the paths (which is not very expensive, especially
compared to any file system operation).