public List<OpBase> getHistory(ESRequest historyRequest)
throws IOException, ResourceNotFoundException, URISyntaxException {
String url = baseUrl + opIndex + "/_search";
String resp = makeESQuery(historyRequest, url);
HistoryResponse historyResponse = objectMapper.readValue(resp, HistoryResponse.class);
List<OpBase> returnMsgList = new ArrayList<>();
historyResponse.tasks.tasks.forEach(editTaskMsgResponse -> {
Map<String, Object> msgObject = editTaskMsgResponse.source.msg;
String taskType = (String) msgObject.get("task_type");
EditTaskType editTaskType = EditTaskType.valueOf(taskType);
switch(editTaskType) {
case MIGRATE_PLACE: returnMsgList.add(objectMapper.readValue(
objectMapper.writeValueAsString(msgObject), MatchingTaskOperatorMetricsMsg.class));
case CURATE_PLACE:
case QC_PLACE: returnMsgList.add(objectMapper.readValue(objectMapper.writeValueAsString(msgObject),
MatchingTaskOperatorMetricsMsg.class));
}
});
return returnMsgList;
}
I get an unhandled IOException exception error with lines like objectMapper.readValue(objectMapper.writeValueAsString(msgObject),
MatchingTaskOperatorMetricsMsg.class));
But I am explicitly saying this method throws this exception?
This warning might be showing withing the lines that's wrapped inside switch-case statements. The one that's outside it would be working fine.
The reason is because that code is inside lambda expression. Unhandled exceptions aren't handled this way in streams and lambda expressions.
You would have to wrap the code written inside lambda expression in try-catch
historyResponse.tasks.tasks.forEach(editTaskMsgResponse -> {
Map<String, Object> msgObject = editTaskMsgResponse.source.msg;
String taskType = (String) msgObject.get("task_type");
EditTaskType editTaskType = EditTaskType.valueOf(taskType);
switch(editTaskType) {
case MIGRATE_PLACE:
try {
returnMsgList.add(objectMapper.readValue(objectMapper.writeValueAsString(msgObject), MatchingTaskOperatorMetricsMsg.class));
}
catch(IOException io) {}
case CURATE_PLACE:
case QC_PLACE:
try {
returnMsgList.add(objectMapper.readValue(objectMapper.writeValueAsString(msgObject), MatchingTaskOperatorMetricsMsg.class));
}
catch(IOException io) {}
}
});
See also:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With