From 1ffc028a3bc94b71abb7dee7c9c5083e92fd93c0 Mon Sep 17 00:00:00 2001 From: Ben Gruver Date: Tue, 5 Jun 2012 13:23:11 -0700 Subject: [PATCH] Add a check to Item.getOffset() and getIndex() to ensure the item has been placed --- dexlib/src/main/java/org/jf/dexlib/Item.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dexlib/src/main/java/org/jf/dexlib/Item.java b/dexlib/src/main/java/org/jf/dexlib/Item.java index f7d03f61..9a2ec5fd 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 @@ public abstract class Item implements Comparable { * @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 @@ public abstract class Item implements Comparable { * @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; }