Skip to content
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

Merged
merged 1 commit into from
Aug 3, 2018
Merged

Update relativize method for java 9 #175

merged 1 commit into from
Aug 3, 2018

Conversation

eatkins
Copy link
Contributor

@eatkins eatkins commented Aug 2, 2018

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).

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"))
Copy link
Member

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.

Copy link
Contributor Author

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.

@typesafe-tools
Copy link

A validation involving this pull request is in progress...

@sbt sbt deleted a comment from typesafe-tools Aug 2, 2018
@eed3si9n
Copy link
Member

eed3si9n commented Aug 2, 2018

Dbuild doesn't work with sbt 1.2.0, so the test result is nonsensical.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants