diff options
author | Joerg Kubitz | 2021-12-10 12:10:26 +0000 |
---|---|---|
committer | Jörg Kubitz | 2021-12-15 07:52:47 +0000 |
commit | 1d2045ac059524c6cb87b0f6004d9ae4669b2d6b (patch) | |
tree | 558b0a2f970022d949ebcd69f0ca707e89461434 | |
parent | 68552872c9c4e978dbe1f77e7c25916c6e5f04c3 (diff) | |
download | eclipse.platform.text-1d2045ac059524c6cb87b0f6004d9ae4669b2d6b.tar.gz eclipse.platform.text-1d2045ac059524c6cb87b0f6004d9ae4669b2d6b.tar.xz eclipse.platform.text-1d2045ac059524c6cb87b0f6004d9ae4669b2d6b.zip |
Bug 577741 - NullPointerException running searchY20211217-0600Y20211216-0600Y20211215-1140Y20211215-0600I20211216-1800I20211215-1800
improved readability, because Exception in lambda is hard to understand
Change-Id: I04e3efec83db734f233e0a0829270a76aa9c52f6
Signed-off-by: Joerg Kubitz <jkubitz-eclipse@gmx.de>
Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.text/+/188739
Tested-by: Platform Bot <platform-bot@eclipse.org>
-rw-r--r-- | org.eclipse.search/search/org/eclipse/search/internal/core/text/TextSearchVisitor.java | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/org.eclipse.search/search/org/eclipse/search/internal/core/text/TextSearchVisitor.java b/org.eclipse.search/search/org/eclipse/search/internal/core/text/TextSearchVisitor.java index 88f846a0ac2..3aabe0aa6c5 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/core/text/TextSearchVisitor.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/core/text/TextSearchVisitor.java @@ -329,14 +329,26 @@ public class TextSearchVisitor { * sort. **/ private static final class FileWithCachedLocation { - final IFile file; - final String location; // cached + private final IFile file; + private final String location; // cached + + private static Comparator<String> NULLS_FIRST = Comparator.nullsFirst(Comparator.naturalOrder()); + private static Comparator<FileWithCachedLocation> BY_LOCATION = Comparator + .comparing(FileWithCachedLocation::getLocation, NULLS_FIRST); FileWithCachedLocation(IFile file) { this.file = file; IPath path = file.getLocation(); // invokes slow OS operation this.location = path == null ? null : path.toString(); } + + String getLocation() { + return location; + } + + IFile getFile() { + return file; + } } public IStatus search(IFile[] files, IProgressMonitor monitor) { @@ -413,7 +425,8 @@ public class TextSearchVisitor { // Sorting files to search by location allows to more easily reuse // search results from one file to the other when they have same location IFile[] filesByLocation = Arrays.stream(files).map(FileWithCachedLocation::new) - .sorted(Comparator.nullsFirst(Comparator.comparing(fn -> fn.location))).map(fn -> fn.file) + .sorted(FileWithCachedLocation.BY_LOCATION) + .map(FileWithCachedLocation::getFile) .collect(Collectors.toList()).toArray(IFile[]::new); for (int first = 0; first < filesByLocation.length; first += filesPerJob) { int end= Math.min(filesByLocation.length, first + filesPerJob); |