Assuming find here is Files.find, what should work for you is
final Path startPath = Paths.get(nasProps.getUpstreamOutputDirectory() +
File.separator +
inputSource.concat("_").concat(contentGroup).concat("_").concat(parentId));
BiPredicate matcher = (filePath, fileAttr) ->
fileAttr.isRegularFile() && filePath.getFileName().toString().matches(".*\." + extTxt);
try (Stream pathStream = Files.find(startPath, Integer.MAX_VALUE, matcher)) {
pathStream.forEach(path -> textFileQueue.add(path));
} catch (IOException e) {
e.printStackTrace(); // handle or add to method calling this block
}
The reason why sonarqube is warning here is mentioned in the API note of linked document as well:
This method must be used within a try-with-resources statement or similar control structure to ensure that the stream's open directories are closed promptly after the stream's operations have completed.