diff options
| author | Muhammad Qureshi <muhammadq@google.com> | 2019-12-08 20:31:01 -0800 |
|---|---|---|
| committer | Muhammad Qureshi <muhammadq@google.com> | 2019-12-08 20:40:46 -0800 |
| commit | 67df8893ddedd51f65482270153a0c65ec104184 (patch) | |
| tree | cc9f8ad0e387c6a214c11be0f0b54c8f8e9cea13 /tools/stats_log_api_gen/java_writer.cpp | |
| parent | 2ee5f0ae287d5a4b4e23b61ba48e5f747dac2b56 (diff) | |
Handle nulls in Java autogeneration
Bug: 143979391
Test: m -j
Change-Id: I93146faa1976cac195c2250832d12ee4a09ae969
Diffstat (limited to 'tools/stats_log_api_gen/java_writer.cpp')
| -rw-r--r-- | tools/stats_log_api_gen/java_writer.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/tools/stats_log_api_gen/java_writer.cpp b/tools/stats_log_api_gen/java_writer.cpp index 4899fbd3b669..d45c4e7efb12 100644 --- a/tools/stats_log_api_gen/java_writer.cpp +++ b/tools/stats_log_api_gen/java_writer.cpp @@ -83,7 +83,7 @@ static int write_java_methods( // Print method body. string indent(""); if (DEFAULT_MODULE_NAME != moduleName) { - fprintf(out, " if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {\n"); + fprintf(out, " if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {\n"); indent = " "; } @@ -116,16 +116,19 @@ static int write_java_methods( fprintf(out, "%s builder.writeString(arg%d);\n", indent.c_str(), argIndex); break; case JAVA_TYPE_BYTE_ARRAY: - fprintf(out, "%s builder.writeByteArray(arg%d);\n", - indent.c_str(), argIndex); + fprintf(out, "%s builder.writeByteArray(null == arg%d ? new byte[0] : arg%d);\n", + indent.c_str(), argIndex, argIndex); break; case JAVA_TYPE_ATTRIBUTION_CHAIN: { const char* uidName = attributionDecl.fields.front().name.c_str(); const char* tagName = attributionDecl.fields.back().name.c_str(); - fprintf(out, "%s builder.writeAttributionChain(%s, %s);\n", - indent.c_str(), uidName, tagName); + fprintf(out, "%s builder.writeAttributionChain(\n", indent.c_str()); + fprintf(out, "%s null == %s ? new int[0] : %s,\n", + indent.c_str(), uidName, uidName); + fprintf(out, "%s null == %s ? new String[0] : %s);\n", + indent.c_str(), tagName, tagName); break; } case JAVA_TYPE_KEY_VALUE_PAIR: |
