Skip to content

Commit

Permalink
Fix getTagsMap generic parameter handling
Browse files Browse the repository at this point in the history
Instead of recovering on ClassCastException to fallback on List
handling, use instanceof to determine the type of tagsMap
  • Loading branch information
jpbempel committed Feb 12, 2020
1 parent 5fbff55 commit 9e309da
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/main/java/org/datadog/jmxfetch/Instance.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,14 @@ private static Map<String, String> getTagsMap(Object tagsMap, AppConfig appConfi
tags.putAll(appConfig.getGlobalTags());
}
if (tagsMap != null) {
try {
// Input has `Map` format
if (tagsMap instanceof Map) {
tags.putAll((Map<String, String>) tagsMap);
} catch (ClassCastException e) {
// Input has `List` format
} else if (tagsMap instanceof List) {
for (String tag : (List<String>) tagsMap) {
tags.put(tag, null);
}
} else {
log.warn("Unsupported type for tagsMap: " + tagsMap.getClass().getCanonicalName());
}
}
return tags;
Expand Down

0 comments on commit 9e309da

Please sign in to comment.