Below is my code:
void deleteTranslationIfUpdated(Stream<MediaTranslation> from, Stream<MediaTranslationDTO> data) { Stream<MediaTranslation> newLogos = data .map(mediaTranslationMapper::mapToEntity) .collect(Collectors.toList()) .stream(); from.filter(e -> newLogos.noneMatch(it -> Objects.equals(e.getLang(), it.getLang()) && Objects.equals(e.getValue().getLink(), it.getValue().getLink()))) .map(MediaTranslation::getValue) .map(Media::getLink) .filter(this::isNotHttpLink) .forEach(storageService::delete); }
The above function is called from the following function:
@Secured({AuthoritiesConstants.USER}) public BrandDTO update(String id, BrandDTO data) throws EntityNotFound { log.debug("Request to update Brand : {} with {}", id, data); return Optional.ofNullable(brandRepository.findOne(id)) .map(from -> { mediaService.deleteTranslationIfUpdated(from.getLogo().stream(), data.getLogo().stream()); return from; }) .map(target -> brandMapper.updateFromDto(data, target)) .map(brandRepository::save) .map(brandMapper::mapToDto) .map(this::copyCategoriesInZone) .orElseThrow(EntityNotFound::new); }
And whenever I do this, I get the following error:
java.lang.IllegalStateException: stream has already been operated upon or closed at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:229) at java.util.stream.ReferencePipeline.noneMatch(ReferencePipeline.java:459) at com.nearbuy.mall.service.MediaService.lambda$deleteTranslationIfUpdated$4(MediaService.java:62)
I get the above error on newLogos.noneMatch ..... :(
I'm not sure why.
source share