summaryrefslogtreecommitdiff
path: root/tools/aapt2/java
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2018-03-05 18:58:43 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2018-03-05 18:58:43 +0000
commit0315c8495db1758dc0acb1fda5cfebfc690889b9 (patch)
treeedba2afd984286c728e85aa8a316d5840e7c6e9c /tools/aapt2/java
parent7264b3484d997a964c64a657bb17a4c77c37cff0 (diff)
parent949b625377188c087f20c13c73efdfe78f16e446 (diff)
Merge "Don't dereference a null pointer"
Diffstat (limited to 'tools/aapt2/java')
-rw-r--r--tools/aapt2/java/JavaClassGenerator.cpp5
-rw-r--r--tools/aapt2/java/JavaClassGenerator_test.cpp18
2 files changed, 21 insertions, 2 deletions
diff --git a/tools/aapt2/java/JavaClassGenerator.cpp b/tools/aapt2/java/JavaClassGenerator.cpp
index 6b07b1e96261..db1561e17f16 100644
--- a/tools/aapt2/java/JavaClassGenerator.cpp
+++ b/tools/aapt2/java/JavaClassGenerator.cpp
@@ -347,7 +347,9 @@ void JavaClassGenerator::ProcessStyleable(const ResourceNameRef& name, const Res
}
// Add the Styleable array to the Styleable class.
- out_class_def->AddMember(std::move(array_def));
+ if (out_class_def != nullptr) {
+ out_class_def->AddMember(std::move(array_def));
+ }
// Now we emit the indices into the array.
for (size_t i = 0; i < attr_count; i++) {
@@ -578,7 +580,6 @@ bool JavaClassGenerator::Generate(const StringPiece& package_name_to_generate,
if (out_r_txt != nullptr) {
r_txt_printer = util::make_unique<Printer>(out_r_txt);
}
-
// Generate an onResourcesLoaded() callback if requested.
if (out != nullptr && options_.rewrite_callback_options) {
rewrite_method =
diff --git a/tools/aapt2/java/JavaClassGenerator_test.cpp b/tools/aapt2/java/JavaClassGenerator_test.cpp
index e449546f9399..10a97d84f59d 100644
--- a/tools/aapt2/java/JavaClassGenerator_test.cpp
+++ b/tools/aapt2/java/JavaClassGenerator_test.cpp
@@ -438,4 +438,22 @@ TEST(JavaClassGeneratorTest, GenerateOnResourcesLoadedCallbackForSharedLibrary)
EXPECT_THAT(output, HasSubstr("com.boo.R.onResourcesLoaded"));
}
+TEST(JavaClassGeneratorTest, OnlyGenerateRText) {
+ std::unique_ptr<ResourceTable> table =
+ test::ResourceTableBuilder()
+ .SetPackageId("android", 0x01)
+ .AddValue("android:attr/foo", ResourceId(0x01010000), util::make_unique<Attribute>())
+ .AddValue("android:styleable/hey.dude", ResourceId(0x01020000),
+ test::StyleableBuilder()
+ .AddItem("android:attr/foo", ResourceId(0x01010000))
+ .Build())
+ .Build();
+
+ std::unique_ptr<IAaptContext> context =
+ test::ContextBuilder().SetPackageId(0x01).SetCompilationPackage("android").Build();
+ JavaClassGenerator generator(context.get(), table.get(), {});
+
+ ASSERT_TRUE(generator.Generate("android", nullptr));
+}
+
} // namespace aapt