OSDN Git Service

Be humane when there are more methods or fields than Dalvik can handle.
authorJesse Wilson <jessewilson@google.com>
Thu, 17 Nov 2011 21:56:51 +0000 (16:56 -0500)
committerJesse Wilson <jessewilson@google.com>
Thu, 17 Nov 2011 22:01:04 +0000 (17:01 -0500)
Previously our errors would look like this:
  trouble writing output: opcode == null
Or this:
  trouble writing output: No expanded opcode for 7f9c1af3

Now our errors look like this:
  trouble writing output: Too many methods: 86922; max is 65536

Bug: http://code.google.com/p/android/issues/detail?id=20814

Change-Id: I2d9dc55e188a6ac1661b74af2194b18019859a29

dx/src/com/android/dx/dex/file/MemberIdsSection.java

index ef0d8cd..ec39b75 100644 (file)
 
 package com.android.dx.dex.file;
 
+import com.android.dx.util.DexException;
+
 /**
  * Member (field or method) refs list section of a {@code .dex} file.
  */
 public abstract class MemberIdsSection extends UniformItemSection {
+    /** The largest addressable member is 0xffff, in the dex spec as field@CCCC or meth@CCCC. */
+    private static final int MAX_MEMBERS = 0x10000;
+
     /**
      * Constructs an instance. The file offset is initially unknown.
      *
@@ -36,6 +41,12 @@ public abstract class MemberIdsSection extends UniformItemSection {
     protected void orderItems() {
         int idx = 0;
 
+        if (items().size() > MAX_MEMBERS) {
+            String memberType = this instanceof MethodIdsSection ? "methods" : "fields";
+            throw new DexException("Too many " + memberType + ": " + items().size()
+                    + "; max is " + MAX_MEMBERS);
+        }
+
         for (Object i : items()) {
             ((MemberIdItem) i).setIndex(idx);
             idx++;