From ebe0944ba6a1ce34bc1de5c76623987d09e6e69a Mon Sep 17 00:00:00 2001 From: Sergey Malenkov Date: Fri, 29 Dec 2017 13:48:16 +0300 Subject: [PATCH] fix NPE while searching in empty JBIterable --- .../impl/nodes/ProjectViewDirectoryHelper.java | 2 +- .../intellij/util/containers/JBIterable.java | 18 +++--------------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/ProjectViewDirectoryHelper.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/ProjectViewDirectoryHelper.java index 29cc77eb7da2..55f2e50bf77d 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/ProjectViewDirectoryHelper.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/nodes/ProjectViewDirectoryHelper.java @@ -176,7 +176,7 @@ public class ProjectViewDirectoryHelper { @NotNull private static JBIterable getParents(PsiDirectory directory, Object owner) { return directory != null && owner instanceof PsiDirectory && PsiTreeUtil.isAncestor((PsiDirectory)owner, directory, true) - ? JBIterable.generate(directory.getParent(), PsiDirectory::getParent).takeWhile(dir -> dir != owner) + ? JBIterable.generate(directory.getParent(), PsiDirectory::getParent).takeWhile(dir -> dir != null && !dir.equals(owner)) : JBIterable.empty(); } diff --git a/platform/util/src/com/intellij/util/containers/JBIterable.java b/platform/util/src/com/intellij/util/containers/JBIterable.java index 530f3f254f70..abde2c4aa107 100644 --- a/platform/util/src/com/intellij/util/containers/JBIterable.java +++ b/platform/util/src/com/intellij/util/containers/JBIterable.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.util.containers; @@ -589,7 +577,7 @@ public abstract class JBIterable implements Iterable { @Nullable public final T first(@NotNull Class type) { E first = first(); - return type.isInstance(first) ? (T)first : null; + return first != null && type.isInstance(first) ? (T)first : null; } /** @@ -598,7 +586,7 @@ public abstract class JBIterable implements Iterable { @Nullable public final E first(@NotNull Condition condition) { E first = first(); - return condition.value(first) ? first : null; + return first != null && condition.value(first) ? first : null; } /**