Add error message on empty public resources
This should provide more understandable behavior in the case described in
https://github.com/bazelbuild/bazel/issues/5077
RELNOTES: none
PiperOrigin-RevId: 193968203
diff --git a/src/tools/android/java/com/google/devtools/build/android/PlaceholderIdFieldInitializerBuilder.java b/src/tools/android/java/com/google/devtools/build/android/PlaceholderIdFieldInitializerBuilder.java
index ab1dee8..571a598 100644
--- a/src/tools/android/java/com/google/devtools/build/android/PlaceholderIdFieldInitializerBuilder.java
+++ b/src/tools/android/java/com/google/devtools/build/android/PlaceholderIdFieldInitializerBuilder.java
@@ -337,13 +337,17 @@
"Cannot force ATTR to have type code other than 0x%02x (got 0x%02x from %s)",
ATTR_TYPE_ID, reservedTypeSlot, previousResource));
}
- allocatedTypeIds.put(currentType, reservedTypeSlot);
- ResourceType alreadyAssigned = assignedIds.put(reservedTypeSlot, currentType);
- if (alreadyAssigned != null) {
- logger.warning(
- String.format(
- "Multiple type names declared for public type identifier 0x%x (%s vs %s)",
- reservedTypeSlot, alreadyAssigned, currentType));
+ if (reservedTypeSlot == null) {
+ logger.warning(String.format("Invalid public resource of type %s - ignoring", currentType));
+ } else {
+ allocatedTypeIds.put(currentType, reservedTypeSlot);
+ ResourceType alreadyAssigned = assignedIds.put(reservedTypeSlot, currentType);
+ if (alreadyAssigned != null) {
+ logger.warning(
+ String.format(
+ "Multiple type names declared for public type identifier 0x%x (%s vs %s)",
+ reservedTypeSlot, alreadyAssigned, currentType));
+ }
}
}
return allocatedTypeIds;