Allow multiple ClassDefItems to share a single empty ClassDataItem
diff --git a/dexlib/src/main/java/org/jf/dexlib/ClassDataItem.java b/dexlib/src/main/java/org/jf/dexlib/ClassDataItem.java
index a675061..3371071 100644
--- a/dexlib/src/main/java/org/jf/dexlib/ClassDataItem.java
+++ b/dexlib/src/main/java/org/jf/dexlib/ClassDataItem.java
@@ -392,6 +392,17 @@
/** {@inheritDoc} */
public int compareTo(ClassDataItem other) {
+ // An empty CodeDataItem may be shared by multiple ClassDefItems, so we can't use parent in this case
+ if (isEmpty()) {
+ if (other.isEmpty()) {
+ return 0;
+ }
+ return -1;
+ }
+ if (other.isEmpty()) {
+ return 1;
+ }
+
if (parent == null) {
if (other.parent == null) {
return 0;
@@ -409,7 +420,7 @@
* @param classDefItem the <code>ClassDefItem</code> that this <code>ClassDataItem</code> is associated with
*/
protected void setParent(ClassDefItem classDefItem) {
- Preconditions.checkState(parent == null || parent.compareTo(classDefItem) == 0);
+ Preconditions.checkState(parent == null || parent.compareTo(classDefItem) == 0 || isEmpty());
parent = classDefItem;
}
@@ -498,6 +509,14 @@
}
/**
+ * @return true if this is an empty ClassDataItem
+ */
+ public boolean isEmpty() {
+ return (getStaticFieldCount() + getInstanceFieldCount() +
+ getDirectMethodCount() + getVirtualMethodCount()) == 0;
+ }
+
+ /**
* Performs a binary search for the definition of the specified direct method
* @param methodIdItem The MethodIdItem of the direct method to search for
* @return The EncodedMethod for the specified direct method, or null if not found