Github user mmiklavc commented on a diff in the pull request:
https://github.com/apache/incubator-metron/pull/445#discussion_r100129984
--- Diff:
metron-platform/metron-common/src/main/java/org/apache/metron/common/utils/ConversionUtils.java
---
@@ -35,6 +35,14 @@ protected ConvertUtilsBean initialValue() {
}
};
+ public static <T> T convertOrFail(Object o, Class<T> clazz) {
+ if (clazz.isInstance(o)) {
--- End diff --
Good point. I'm removing this entirely. I'll just use casting in place, e.g.
**Example 1**
`String val = (String) map.get("foo"); // throws class cast exception on
failure, which is what we want`
**Example 2**
```
Map<Object, Object> a = new HashMap() {{
put("hello", "world");
put(1, 2);
}};
Map<String, Object> b = new HashMap() {{
put("a", a);
}};
Map<Object, Object> c = (Map) b.get("a"); // throws class cast exception if
not a Map
Map<String, String> d = new HashMap<>();
for (Map.Entry<Object, Object> entry : c.entrySet()) {
d.put((String) entry.getKey(), (String) entry.getValue()); // throws
class cast exception. also what we want
}
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---