fix NPE while searching in empty JBIterable

This commit is contained in:
Sergey Malenkov
2017-12-29 13:50:40 +03:00
parent 4b5411f21e
commit ebe0944ba6
2 changed files with 4 additions and 16 deletions
@@ -176,7 +176,7 @@ public class ProjectViewDirectoryHelper {
@NotNull
private static JBIterable<PsiDirectory> 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();
}
@@ -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<E> implements Iterable<E> {
@Nullable
public final <T> T first(@NotNull Class<T> 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<E> implements Iterable<E> {
@Nullable
public final E first(@NotNull Condition<? super E> condition) {
E first = first();
return condition.value(first) ? first : null;
return first != null && condition.value(first) ? first : null;
}
/**