Add a check to Item.getOffset() and getIndex() to ensure the item has been placed
diff --git a/dexlib/src/main/java/org/jf/dexlib/Item.java b/dexlib/src/main/java/org/jf/dexlib/Item.java
index f7d03f6..9a2ec5f 100644
--- a/dexlib/src/main/java/org/jf/dexlib/Item.java
+++ b/dexlib/src/main/java/org/jf/dexlib/Item.java
@@ -28,6 +28,7 @@
package org.jf.dexlib;
+import com.google.common.base.Preconditions;
import org.jf.dexlib.Util.AlignmentUtils;
import org.jf.dexlib.Util.AnnotatedOutput;
import org.jf.dexlib.Util.ExceptionWithContext;
@@ -191,6 +192,8 @@
* @return the offset in the dex file where this item is located
*/
public int getOffset() {
+ Preconditions.checkState(offset != -1,
+ "The offset is not set until the DexFile containing this item is placed.");
return offset;
}
@@ -198,6 +201,8 @@
* @return the index of this item within the item's containing section
*/
public int getIndex() {
+ Preconditions.checkState(index != -1,
+ "The index is not set until the DexFile containing this item is placed.");
return index;
}