IllegalArgumentException when union fails to read
Currently, it throws RuntimeException. But, RuntimeException is
misinterpreted by the other side as "unimplemented method",
which makes the proxy fall back to default implementation and
re-throw "Method xxx is unimplemented" exception.
Throwing IllegalArgumentException can fix it. However, we still have an
asymmetry among backend types. The native sides returns BAD_VALUE when
it fails to read a union from a Parcel, which is translated into
IllegalArgumentException from the Java backend. But when the Java side
throws IllegalArgumentException, it is interpreted as
ILLEGAL_ARGUMENT_EX from the native backends.
Bug: 173458620
Test: aidl_unittests
Change-Id: I47a3ad7d2d7030b90e796a215d7b483492e5efec
diff --git a/aidl_unittest.cpp b/aidl_unittest.cpp
index 3eb9eb9..a4209c0 100644
--- a/aidl_unittest.cpp
+++ b/aidl_unittest.cpp
@@ -3476,7 +3476,7 @@
_set(_aidl_tag, _aidl_value);
return; }
}
- throw new RuntimeException("union: out of range: " + _aidl_tag);
+ throw new IllegalArgumentException("union: unknown tag: " + _aidl_tag);
}
@Override