Don't call a method that can be overridden from File's constructors.
Bug: 2486943
diff --git a/libcore/luni/src/main/java/java/io/File.java b/libcore/luni/src/main/java/java/io/File.java
index 553206d..2910f91 100644
--- a/libcore/luni/src/main/java/java/io/File.java
+++ b/libcore/luni/src/main/java/java/io/File.java
@@ -200,7 +200,8 @@
// Keep a copy of the cleaned-up string path.
this.path = fixSlashes(dirtyPath);
// Cache the UTF-8 bytes we need for the JNI.
- if (isAbsolute()) {
+ // TODO: we shouldn't do this caching at all; the RI demonstrably doesn't.
+ if (path.length() > 0 && path.charAt(0) == separatorChar) { // http://b/2486943
this.pathBytes = newCString(path);
return;
}
diff --git a/libcore/luni/src/test/java/java/io/FileTest.java b/libcore/luni/src/test/java/java/io/FileTest.java
index d7ffaac..0518c26 100644
--- a/libcore/luni/src/test/java/java/io/FileTest.java
+++ b/libcore/luni/src/test/java/java/io/FileTest.java
@@ -115,4 +115,21 @@
assertEquals(new File(cwd), f.getCanonicalFile());
assertEquals(cwd, f.getCanonicalPath());
}
+
+ // http://b/2486943 - between eclair and froyo, we added a call to
+ // isAbsolute from the File constructor, potentially breaking subclasses.
+ public void test_subclassing() throws Exception {
+ class MyFile extends File {
+ private String field;
+ MyFile(String s) {
+ super(s);
+ field = "";
+ }
+ @Override public boolean isAbsolute() {
+ field.length();
+ return super.isAbsolute();
+ }
+ }
+ new MyFile("");
+ }
}