Menu

#1353 False positive "Only One Return" with lambda

PMD-5.3.2
closed
None
PMD
3-Major
Bug
5.3.1
2015-05-13
2015-05-13
Rei Angelus
No

With java 8, when a method contains a lambda expression with a return, the return of the lambda is counted as a return of the method.

For example :
:::java
public Try<SearchHit[]> search(final String indexName, final SearchRequest searchRequest) {
final SearchHit[] empty = new SearchHit[0];
final Optional<SearchDefinition> searchDefinition = settingsService.getSearchDefinition(indexName);
return searchDefinition.<Try<SearchHit[]>>map(
i -> {
final List<Try<ProviderSearchHit[]>> res = i.getSearchMapping().stream()
.peek(m -> LOGGER.debug("Treating backend \"{}\"", m.getProviderRef()))
.map(m -> invokeAdapter(getProviderSearchService(m.getProviderRef()), m, searchRequest))
.collect(Collectors.toList());
return TryCollections.pull(res).map(l -> sortReturning(l.stream().collect(ArrayCollectors.arrayMerging(
SearchServiceImpl::toSearchHit,
SearchHit::getInternalId,
Function.identity(),
SearchServiceImpl::merge)).orElse(Collections.emptyList()), SearchServiceImpl.searchHitComparator()))
.map(list -> list.toArray(empty));
}).orElse(Try.success(empty));
}

One return for the lambda, one return for the method but false positive "Only One Return"

Discussion

  • Andreas Dangel

    Andreas Dangel - 2015-05-13
    • status: open --> closed
    • assigned_to: Andreas Dangel
    • Milestone: New Tickets --> PMD-5.3.2
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.