Merge changes I3ff513f8,I35a771f5
* changes:
Disallow construction of DexPathList.Element with path == dexFile == null.
Avoid I/O during DexPathList.Element.toString().
diff --git a/dalvik/src/main/java/dalvik/system/DexPathList.java b/dalvik/src/main/java/dalvik/system/DexPathList.java
index 73e40f2..adc7cf4 100644
--- a/dalvik/src/main/java/dalvik/system/DexPathList.java
+++ b/dalvik/src/main/java/dalvik/system/DexPathList.java
@@ -624,6 +624,8 @@
*/
@UnsupportedAppUsage
private final File path;
+ /** Whether {@code path.isDirectory()}, or {@code null} if {@code path == null}. */
+ private final Boolean pathIsDirectory;
@UnsupportedAppUsage
private final DexFile dexFile;
@@ -637,18 +639,21 @@
*/
@UnsupportedAppUsage
public Element(DexFile dexFile, File dexZipPath) {
+ if (dexFile == null && dexZipPath == null) {
+ throw new NullPointerException("Either dexFile or path must be non-null");
+ }
this.dexFile = dexFile;
this.path = dexZipPath;
+ // Do any I/O in the constructor so we don't have to do it elsewhere, eg. toString().
+ this.pathIsDirectory = (path == null) ? null : path.isDirectory();
}
public Element(DexFile dexFile) {
- this.dexFile = dexFile;
- this.path = null;
+ this(dexFile, null);
}
public Element(File path) {
- this.path = path;
- this.dexFile = null;
+ this(null, path);
}
/**
@@ -662,6 +667,7 @@
@UnsupportedAppUsage
@Deprecated
public Element(File dir, boolean isDirectory, File zip, DexFile dexFile) {
+ this(dir != null ? null : dexFile, dir != null ? dir : zip);
System.err.println("Warning: Using deprecated Element constructor. Do not use internal"
+ " APIs, this constructor will be removed in the future.");
if (dir != null && (zip != null || dexFile != null)) {
@@ -671,13 +677,6 @@
if (isDirectory && (zip != null || dexFile != null)) {
throw new IllegalArgumentException("Unsupported argument combination.");
}
- if (dir != null) {
- this.path = dir;
- this.dexFile = null;
- } else {
- this.path = zip;
- this.dexFile = dexFile;
- }
}
/*
@@ -696,13 +695,9 @@
@Override
public String toString() {
if (dexFile == null) {
- return (path.isDirectory() ? "directory \"" : "zip file \"") + path + "\"";
+ return (pathIsDirectory ? "directory \"" : "zip file \"") + path + "\"";
} else {
- if (path == null) {
- return "dex file \"" + dexFile + "\"";
- } else {
- return "zip file \"" + path + "\"";
- }
+ return "zip file \"" + path + "\"";
}
}
@@ -711,7 +706,7 @@
return;
}
- if (path == null || path.isDirectory()) {
+ if (path == null || pathIsDirectory) {
initialized = true;
return;
}