aboutsummaryrefslogtreecommitdiff
path: root/Interface.cpp
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-07-07 05:23:45 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-07-07 05:23:45 +0000
commit9b7b7ae28ec32d5c6f47500896552c3d1f1028d0 (patch)
tree74e45a722ffd775127a136c27e0c2b8659adc7e9 /Interface.cpp
parent5c7e328078a3bb592fb73cd5a009bcf759c57c52 (diff)
parent5ba9115da292a2527e8aeac19cef35d468173f85 (diff)
downloadhidl-9b7b7ae28ec32d5c6f47500896552c3d1f1028d0.tar.gz
Change-Id: I15efd9312f508313badef8743e620f6cd1614ca2
Diffstat (limited to 'Interface.cpp')
-rw-r--r--Interface.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/Interface.cpp b/Interface.cpp
index 9be88e9f..e9950d22 100644
--- a/Interface.cpp
+++ b/Interface.cpp
@@ -307,9 +307,15 @@ bool Interface::fillHashChainMethod(Method *method) const {
} } }, /* cppImpl */
{ { IMPL_INTERFACE, [this, digestType, chainType](auto &out) {
std::vector<const Interface *> chain = typeChain();
- out << "return new "
- << chainType->getJavaType(false /* forInitializer */)
- << "(java.util.Arrays.asList(\n";
+ out << "return new " << chainType->getJavaType(false /* forInitializer */);
+ if (chain.size() == 1) {
+ // https://errorprone.info/bugpattern/ArraysAsListPrimitiveArray
+ // To avoid an ArraysAsListPrimitiveArray errorprone error, use
+ // singletonList when there's only 1 element in the chain.
+ out << "(java.util.Collections.singletonList(\n";
+ } else {
+ out << "(java.util.Arrays.asList(\n";
+ }
out.indent(2, [&] {
// No need for dimensions when elements are explicitly provided.
emitDigestChain(out, "new " + digestType->getJavaType(false /* forInitializer */),