diff --git a/dexlib/src/main/java/org/jf/dexlib/ClassDataItem.java b/dexlib/src/main/java/org/jf/dexlib/ClassDataItem.java index a6750611..33710710 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 @@ public class ClassDataItem extends Item { /** {@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 @@ public class ClassDataItem extends Item { * @param classDefItem the ClassDefItem that this ClassDataItem 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; } @@ -497,6 +508,14 @@ public class ClassDataItem extends Item { return virtualMethods.length; } + /** + * @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