URI base = new URI("http://hostname/root"); URI uri = new URI("http://hostname/root/yyy/zzz.html"); URI rel = base.relativize(uri);
上記コードのrelは
yyy/zzz.html
となるのが正しい挙動(Javaではそうなる)のはずだが、
Android 8ではroot/yyy/zzz.html が返ってくる。
調べてみると、Androidのrerativizeのソースにこの挙動が明記されていた
// Android-changed: The original OpenJdk implementation would append a trailing slash
// to paths like "/a/b" before relativizing them. This would relativize /a/b/c to
// "/c" against "/a/b" the android implementation did not do this. It would assume that
// "b" wasn't a directory and relativize the path to "/b/c". The spec is pretty vague
// about this but this change is being made because we have several tests that expect
// this behaviour.
解決策はない? 自分はhttp://www.devx.com/tips/Tip/13737 を使うことにした