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 11, 2020
1 parent 06092cb commit 55d1593
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 @@ -320,14 +320,14 @@ private static LinkedHashMap<String, String> getTagsMap(Object tagsMap, 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 55d1593

Please sign in to comment.