Throw android.os.BadParcelableException when parcelable too large

Instead of returning false.

Test: m
Bug: none - brought up in aosp/3147023 comments
Change-Id: I240674ab27c39dfa8a90c85594da8f217df8ceff
diff --git a/generate_java_binder.cpp b/generate_java_binder.cpp
index e5561ff..343cbd6 100644
--- a/generate_java_binder.cpp
+++ b/generate_java_binder.cpp
@@ -611,7 +611,8 @@
           (*writer) << "int " << var_length << " = data.readInt();\n";
           // if impossibly large array requested, return false
           (*writer) << "if (" << var_length << " > 1000000) {\n";
-          (*writer) << "  return false;\n";
+          (*writer) << "  throw new android.os.BadParcelableException(\"Array too large: \" + "
+                    << var_length << ");\n";
           (*writer) << "} else if (" << var_length << " < 0) {\n";
           (*writer) << "  " << v->name << " = null;\n";
           (*writer) << "} else {\n";
diff --git a/tests/golden_output/aidl-cpp-java-test-interface-java-source/gen/android/aidl/tests/ICppJavaTests.java b/tests/golden_output/aidl-cpp-java-test-interface-java-source/gen/android/aidl/tests/ICppJavaTests.java
index 69fed98..7ed4f60 100644
--- a/tests/golden_output/aidl-cpp-java-test-interface-java-source/gen/android/aidl/tests/ICppJavaTests.java
+++ b/tests/golden_output/aidl-cpp-java-test-interface-java-source/gen/android/aidl/tests/ICppJavaTests.java
@@ -175,7 +175,7 @@
           android.os.PersistableBundle[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
@@ -231,7 +231,7 @@
           java.io.FileDescriptor[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
diff --git a/tests/golden_output/aidl-test-interface-java-source/gen/android/aidl/tests/ArrayOfInterfaces.java b/tests/golden_output/aidl-test-interface-java-source/gen/android/aidl/tests/ArrayOfInterfaces.java
index 45fdd79..bf3c430 100644
--- a/tests/golden_output/aidl-test-interface-java-source/gen/android/aidl/tests/ArrayOfInterfaces.java
+++ b/tests/golden_output/aidl-test-interface-java-source/gen/android/aidl/tests/ArrayOfInterfaces.java
@@ -223,7 +223,7 @@
             android.aidl.tests.ArrayOfInterfaces.IEmptyInterface[] _arg3;
             int _arg3_length = data.readInt();
             if (_arg3_length > 1000000) {
-              return false;
+              throw new android.os.BadParcelableException("Array too large: " + _arg3_length);
             } else if (_arg3_length < 0) {
               _arg3 = null;
             } else {
@@ -236,7 +236,7 @@
             android.aidl.tests.ArrayOfInterfaces.IEmptyInterface[] _arg6;
             int _arg6_length = data.readInt();
             if (_arg6_length > 1000000) {
-              return false;
+              throw new android.os.BadParcelableException("Array too large: " + _arg6_length);
             } else if (_arg6_length < 0) {
               _arg6 = null;
             } else {
diff --git a/tests/golden_output/aidl-test-interface-java-source/gen/android/aidl/tests/ITestService.java b/tests/golden_output/aidl-test-interface-java-source/gen/android/aidl/tests/ITestService.java
index ebc333b..10284b0 100644
--- a/tests/golden_output/aidl-test-interface-java-source/gen/android/aidl/tests/ITestService.java
+++ b/tests/golden_output/aidl-test-interface-java-source/gen/android/aidl/tests/ITestService.java
@@ -1104,7 +1104,7 @@
           boolean[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
@@ -1124,7 +1124,7 @@
           byte[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
@@ -1144,7 +1144,7 @@
           char[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
@@ -1164,7 +1164,7 @@
           int[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
@@ -1184,7 +1184,7 @@
           long[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
@@ -1204,7 +1204,7 @@
           float[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
@@ -1224,7 +1224,7 @@
           double[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
@@ -1244,7 +1244,7 @@
           java.lang.String[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
@@ -1264,7 +1264,7 @@
           byte[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
@@ -1284,7 +1284,7 @@
           int[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
@@ -1304,7 +1304,7 @@
           long[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
@@ -1447,7 +1447,7 @@
           android.os.ParcelFileDescriptor[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
@@ -1622,7 +1622,7 @@
           java.lang.String[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
@@ -1642,7 +1642,7 @@
           java.lang.String[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
@@ -1717,7 +1717,7 @@
           android.os.IBinder[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
@@ -1737,7 +1737,7 @@
           android.os.IBinder[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
@@ -1770,7 +1770,7 @@
           android.aidl.tests.SimpleParcelable[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
diff --git a/tests/golden_output/frozen/aidl-cpp-java-test-interface-java-source/gen/android/aidl/tests/ICppJavaTests.java b/tests/golden_output/frozen/aidl-cpp-java-test-interface-java-source/gen/android/aidl/tests/ICppJavaTests.java
index 69fed98..7ed4f60 100644
--- a/tests/golden_output/frozen/aidl-cpp-java-test-interface-java-source/gen/android/aidl/tests/ICppJavaTests.java
+++ b/tests/golden_output/frozen/aidl-cpp-java-test-interface-java-source/gen/android/aidl/tests/ICppJavaTests.java
@@ -175,7 +175,7 @@
           android.os.PersistableBundle[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
@@ -231,7 +231,7 @@
           java.io.FileDescriptor[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
diff --git a/tests/golden_output/frozen/aidl-test-interface-java-source/gen/android/aidl/tests/ArrayOfInterfaces.java b/tests/golden_output/frozen/aidl-test-interface-java-source/gen/android/aidl/tests/ArrayOfInterfaces.java
index 45fdd79..bf3c430 100644
--- a/tests/golden_output/frozen/aidl-test-interface-java-source/gen/android/aidl/tests/ArrayOfInterfaces.java
+++ b/tests/golden_output/frozen/aidl-test-interface-java-source/gen/android/aidl/tests/ArrayOfInterfaces.java
@@ -223,7 +223,7 @@
             android.aidl.tests.ArrayOfInterfaces.IEmptyInterface[] _arg3;
             int _arg3_length = data.readInt();
             if (_arg3_length > 1000000) {
-              return false;
+              throw new android.os.BadParcelableException("Array too large: " + _arg3_length);
             } else if (_arg3_length < 0) {
               _arg3 = null;
             } else {
@@ -236,7 +236,7 @@
             android.aidl.tests.ArrayOfInterfaces.IEmptyInterface[] _arg6;
             int _arg6_length = data.readInt();
             if (_arg6_length > 1000000) {
-              return false;
+              throw new android.os.BadParcelableException("Array too large: " + _arg6_length);
             } else if (_arg6_length < 0) {
               _arg6 = null;
             } else {
diff --git a/tests/golden_output/frozen/aidl-test-interface-java-source/gen/android/aidl/tests/ITestService.java b/tests/golden_output/frozen/aidl-test-interface-java-source/gen/android/aidl/tests/ITestService.java
index ebc333b..10284b0 100644
--- a/tests/golden_output/frozen/aidl-test-interface-java-source/gen/android/aidl/tests/ITestService.java
+++ b/tests/golden_output/frozen/aidl-test-interface-java-source/gen/android/aidl/tests/ITestService.java
@@ -1104,7 +1104,7 @@
           boolean[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
@@ -1124,7 +1124,7 @@
           byte[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
@@ -1144,7 +1144,7 @@
           char[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
@@ -1164,7 +1164,7 @@
           int[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
@@ -1184,7 +1184,7 @@
           long[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
@@ -1204,7 +1204,7 @@
           float[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
@@ -1224,7 +1224,7 @@
           double[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
@@ -1244,7 +1244,7 @@
           java.lang.String[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
@@ -1264,7 +1264,7 @@
           byte[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
@@ -1284,7 +1284,7 @@
           int[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
@@ -1304,7 +1304,7 @@
           long[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
@@ -1447,7 +1447,7 @@
           android.os.ParcelFileDescriptor[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
@@ -1622,7 +1622,7 @@
           java.lang.String[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
@@ -1642,7 +1642,7 @@
           java.lang.String[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
@@ -1717,7 +1717,7 @@
           android.os.IBinder[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
@@ -1737,7 +1737,7 @@
           android.os.IBinder[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {
@@ -1770,7 +1770,7 @@
           android.aidl.tests.SimpleParcelable[] _arg1;
           int _arg1_length = data.readInt();
           if (_arg1_length > 1000000) {
-            return false;
+            throw new android.os.BadParcelableException("Array too large: " + _arg1_length);
           } else if (_arg1_length < 0) {
             _arg1 = null;
           } else {