I was trying the following code:
Optional.ofNullable(listEvidence).ifPresent(
eviList -> {
List<String> repoKeysList = new ArrayList<String>();
for (Evidence evidence : eviList) {
repoKeysList.add(evidence.getRepositoryKey());
}
log.debug("UserContentBean: processRepoSyncCleanup repoKeysList - "+repoKeysList);
evidenceDetailDAO.updateIsSelectedFlag(repoKeysList, 0,configurationService.getNodeName());
}
).orElseThrow();
but I am getting the following error:
Cannot invoke orElseThrow() on the primitive type void
It seems to me that orElseThrow()
is misplaced in the code. but updateIsSelectedFlag()
throws an exception which needs to be handled.
Also, this piece of code is a part of, say, method1()
. I tried adding throws Exception to method1()
, but it yet asks me to handle the exception raised by updateIsSelectedFlag()
. I couldn't understand the reason for the same.