diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootModelBase.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootModelBase.java index f07a8c224ca2..5b890e4cfab6 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootModelBase.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootModelBase.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2015 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.openapi.roots.impl; @@ -206,7 +194,7 @@ public abstract class RootModelBase implements ModuleRootModel { @NotNull public Module[] getModuleDependencies(boolean includeTests) { OrderEntry[] entries = getOrderEntries(); - List result = new ArrayList<>(entries.length); + List result = null; for (OrderEntry entry : entries) { if (entry instanceof ModuleOrderEntry) { @@ -214,13 +202,16 @@ public abstract class RootModelBase implements ModuleRootModel { if (includeTests || scope.isForProductionCompile() || scope.isForProductionRuntime()) { Module module = ((ModuleOrderEntry)entry).getModule(); if (module != null) { + if (result == null) { + result = new SmartList<>(); + } result.add(module); } } } } - return result.isEmpty() ? Module.EMPTY_ARRAY : ContainerUtil.toArray(result, new Module[result.size()]); + return result == null ? Module.EMPTY_ARRAY : ContainerUtil.toArray(result, new Module[result.size()]); } private static class CollectDependentModules extends RootPolicy> {