From 0e718fbaabe750fb802403ef5e63ad36bc4ca628 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Thu, 4 Jun 2015 10:59:09 +0300 Subject: [PATCH] Introduce UNKNOWN visibility as default in FunctionDescriptor It's needed to prevent NPE when requesting non-nullable visibility of descriptor before `initialize` has been called. Currently it happens because of indirect calls of `DescriptorUtils.isLocal` between descriptor creation and it's initialization. --- .../kotlin/descriptors/Visibilities.java | 16 ++++++++++++++++ .../descriptors/impl/FunctionDescriptorImpl.java | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/Visibilities.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/Visibilities.java index 01b986f62f3..6a5c86ba58b 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/Visibilities.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/Visibilities.java @@ -173,6 +173,22 @@ public class Visibilities { } }; + // Currently used as default visibility of FunctionDescriptor + // It's needed to prevent NPE when requesting non-nullable visibility of descriptor before `initialize` has been called + public static final Visibility UNKNOWN = new Visibility("unknown", false) { + @Override + public boolean mustCheckInImports() { + throw new IllegalStateException("This method shouldn't be invoked for UNKNOWN visibility"); + } + + @Override + protected boolean isVisible( + @NotNull ReceiverValue receiver, @NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from + ) { + return false; + } + }; + public static final Set INVISIBLE_FROM_OTHER_MODULES = Collections.unmodifiableSet(KotlinPackage.setOf(PRIVATE, PRIVATE_TO_THIS, INTERNAL, LOCAL)); diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/FunctionDescriptorImpl.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/FunctionDescriptorImpl.java index 860481ec584..3ce0941e14b 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/FunctionDescriptorImpl.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/FunctionDescriptorImpl.java @@ -40,7 +40,7 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo private ReceiverParameterDescriptor extensionReceiverParameter; private ReceiverParameterDescriptor dispatchReceiverParameter; private Modality modality; - private Visibility visibility; + private Visibility visibility = Visibilities.UNKNOWN; private final Set overriddenFunctions = new LinkedHashSet(); // LinkedHashSet is essential here private final FunctionDescriptor original; private final Kind kind;