From d88724cc7b76fce33d2ce92dff2c1e6e144dd2d7 Mon Sep 17 00:00:00 2001 From: Sergey Ignatov Date: Sat, 17 Dec 2016 18:05:52 +0300 Subject: [PATCH] fix NPE ava.lang.NullPointerException: element cannot be mapped to a null key at java.util.Objects.requireNonNull(Objects.java:228) at java.util.stream.Collectors.lambda$groupingBy$45(Collectors.java:907) at java.util.stream.ReduceOps$3ReducingSink.accept(ReduceOps.java:169) at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) at com.intellij.openapi.vcs.changes.ChangesUtil$4.compute(ChangesUtil.java:304) at com.intellij.openapi.vcs.changes.ChangesUtil$4.compute(ChangesUtil.java:300) at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:895) at com.intellij.openapi.vcs.changes.ChangesUtil.processItemsByVcs(ChangesUtil.java:299) at com.intellij.openapi.vcs.changes.ChangesUtil.processVirtualFilesByVcs(ChangesUtil.java:324) at com.intellij.openapi.vcs.changes.actions.EditAction.editFiles(EditAction.java:55) at com.intellij.openapi.vcs.changes.actions.EditAction.editFilesAndShowErrors(EditAction.java:48) --- .../openapi/vcs/changes/ChangesUtil.java | 42 +++++++------------ 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/changes/ChangesUtil.java b/platform/vcs-api/src/com/intellij/openapi/vcs/changes/ChangesUtil.java index dc3455576985..f52397b69f91 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/changes/ChangesUtil.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/changes/ChangesUtil.java @@ -201,13 +201,9 @@ public class ChangesUtil { public static FilePath getLocalPath(@NotNull Project project, FilePath filePath) { // check if the file has just been renamed (IDEADEV-15494) - Change change = ApplicationManager.getApplication().runReadAction(new Computable() { - @Override - @Nullable - public Change compute() { - if (project.isDisposed()) throw new ProcessCanceledException(); - return ChangeListManager.getInstance(project).getChange(filePath); - } + Change change = ApplicationManager.getApplication().runReadAction((Computable)() -> { + if (project.isDisposed()) throw new ProcessCanceledException(); + return ChangeListManager.getInstance(project).getChange(filePath); }); if (change != null) { ContentRevision beforeRevision = change.getBeforeRevision(); @@ -242,20 +238,17 @@ public class ChangesUtil { @Nullable private static VirtualFile getValidParentUnderReadAction(@NotNull FilePath filePath) { - return ApplicationManager.getApplication().runReadAction(new Computable() { - @Override - public VirtualFile compute() { - VirtualFile result = null; - FilePath parent = filePath; - LocalFileSystem lfs = LocalFileSystem.getInstance(); + return ApplicationManager.getApplication().runReadAction((Computable)() -> { + VirtualFile result = null; + FilePath parent = filePath; + LocalFileSystem lfs = LocalFileSystem.getInstance(); - while (result == null && parent != null) { - result = lfs.findFileByPath(parent.getPath()); - parent = parent.getParentPath(); - } - - return result; + while (result == null && parent != null) { + result = lfs.findFileByPath(parent.getPath()); + parent = parent.getParentPath(); } + + return result; }); } @@ -297,13 +290,10 @@ public class ChangesUtil { @NotNull VcsSeparator separator, @NotNull PerVcsProcessor processor) { Map> changesByVcs = ApplicationManager.getApplication().runReadAction( - new NotNullComputable>>() { - @NotNull - @Override - public Map> compute() { - return items.stream().collect(groupingBy(separator::getVcsFor)); - } - }); + (NotNullComputable>>)() -> + items.stream() + .filter(it -> separator.getVcsFor(it) != null) + .collect(groupingBy(separator::getVcsFor))); changesByVcs.forEach((vcs, vcsItems) -> { if (vcs != null) {