Fail if the new index is out of range. do not merge.
We were silently truncating, which made an obvious problem
into a non-obvious one.
Bug: http://code.google.com/p/android/issues/detail?id=40409
(cherry picked from commit 0a752f071fbbdfeab5dd9a230efe0f4f47b8cd94)
Change-Id: I6adbe6309bdcb2882f0e5500d6e1e149d08dbd2d
diff --git a/dx/src/com/android/dx/merge/DexMerger.java b/dx/src/com/android/dx/merge/DexMerger.java
index fc4d145..b7677cf 100644
--- a/dx/src/com/android/dx/merge/DexMerger.java
+++ b/dx/src/com/android/dx/merge/DexMerger.java
@@ -406,6 +406,9 @@
}
@Override void updateIndex(int offset, IndexMap indexMap, int oldIndex, int newIndex) {
+ if (newIndex < 0 || newIndex > 0xffff) {
+ throw new IllegalArgumentException("type ID not in [0, 0xffff]: " + newIndex);
+ }
indexMap.typeIds[oldIndex] = (short) newIndex;
}
@@ -446,6 +449,9 @@
}
@Override void updateIndex(int offset, IndexMap indexMap, int oldIndex, int newIndex) {
+ if (newIndex < 0 || newIndex > 0xffff) {
+ throw new IllegalArgumentException("proto ID not in [0, 0xffff]: " + newIndex);
+ }
indexMap.protoIds[oldIndex] = (short) newIndex;
}
@@ -466,6 +472,9 @@
}
@Override void updateIndex(int offset, IndexMap indexMap, int oldIndex, int newIndex) {
+ if (newIndex < 0 || newIndex > 0xffff) {
+ throw new IllegalArgumentException("field ID not in [0, 0xffff]: " + newIndex);
+ }
indexMap.fieldIds[oldIndex] = (short) newIndex;
}
@@ -486,6 +495,9 @@
}
@Override void updateIndex(int offset, IndexMap indexMap, int oldIndex, int newIndex) {
+ if (newIndex < 0 || newIndex > 0xffff) {
+ throw new IllegalArgumentException("method ID not in [0, 0xffff]: " + newIndex);
+ }
indexMap.methodIds[oldIndex] = (short) newIndex;
}