aboutsummaryrefslogtreecommitdiff
path: root/ArrayType.cpp
diff options
context:
space:
mode:
authorAndreas Huber <andih@google.com>2018-08-03 13:54:41 -0700
committerSteven Moreland <smoreland@google.com>2018-09-19 22:53:25 +0000
commit2dafb927508ecfc57b14f966fa4728ac2f1038cc (patch)
treee6a183b3f2ab123ff023a5e990358a0988bfc49c /ArrayType.cpp
parent492bada1b47958765a940e7e28258176ecc4bc10 (diff)
downloadhidl-2dafb927508ecfc57b14f966fa4728ac2f1038cc.tar.gz
Verify that Java supplied primitive arrays match the dimensions of the
corresponding hidl type. Also a) fixes existing Java client tests for primitive arrays that weren't testing anything before. b) adds a new test that verifies that passing vectors of primitive arrays of mismatched lengths will actually fail. Bug: 112109243 Test: hidl device tests Change-Id: Ib34f37815bc351e4c4355fc4b4b841b9a45c2e91
Diffstat (limited to 'ArrayType.cpp')
-rw-r--r--ArrayType.cpp27
1 files changed, 26 insertions, 1 deletions
diff --git a/ArrayType.cpp b/ArrayType.cpp
index 98359683..9fdc27c2 100644
--- a/ArrayType.cpp
+++ b/ArrayType.cpp
@@ -512,13 +512,38 @@ void ArrayType::emitJavaFieldReaderWriter(
<< mSizes.back()->javaValue()
<< " /* size */);\n";
} else {
+ std::string elemName = "_hidl_array_item_" + std::to_string(depth);
+
+ out << mElementType->getJavaType(false /* forInitializer */)
+ << "[] "
+ << elemName
+ << " = "
+ << fieldNameWithCast
+ << ";\n\n";
+
+ out << "if ("
+ << elemName
+ << " == null || "
+ << elemName
+ << ".length != "
+ << mSizes.back()->javaValue()
+ << ") {\n";
+
+ out.indent();
+
+ out << "throw new IllegalArgumentException("
+ << "\"Array element is not of the expected length\");\n";
+
+ out.unindent();
+ out << "}\n\n";
+
out << blobName
<< ".put"
<< mElementType->getJavaSuffix()
<< "Array("
<< offsetName
<< ", "
- << fieldNameWithCast
+ << elemName
<< ");\n";
}