[terminal] IDEA-348915 Fix NPE when the new terminal survey dialog opened for test

There can be no info about most used shell only if the dialog is opened by the testing action. In the real scenario, the dialog just won't be shown if there are no executed commands because of the check in `BlockTerminalSurveyConfig.checkExtraConditionSatisfied`.
EA-1151653 fixed.

GitOrigin-RevId: f751b6dcaf46fa67bff26cbf4f3334312ed6b2f5
This commit is contained in:
Konstantin Hudyakov
2024-04-03 10:15:12 +00:00
committed by intellij-monorepo-bot
parent 622a7368cd
commit 23bf09e3a0
2 changed files with 14 additions and 3 deletions
@@ -15,8 +15,9 @@ internal class TerminalUsageLocalStorage : PersistentStateComponent<TerminalUsag
val executedCommandsNumber: Int
get() = state.shellToExecutedCommandsNumber.values.sum()
val mostUsedShell: String
get() = state.shellToExecutedCommandsNumber.keys.maxBy { state.shellToExecutedCommandsNumber[it]!! }
/** Can be null only if [executedCommandsNumber] is zero */
val mostUsedShell: String?
get() = state.shellToExecutedCommandsNumber.keys.maxByOrNull { state.shellToExecutedCommandsNumber[it]!! }
fun recordCommandExecuted(shellName: String) {
state.shellToExecutedCommandsNumber.merge(shellName.lowercase(), 1, Int::plus)
@@ -1,6 +1,7 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.plugins.terminal.exp.feedback
import com.intellij.openapi.diagnostic.thisLogger
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.NlsSafe
import com.intellij.platform.feedback.dialog.BlockBasedFeedbackDialog
@@ -23,9 +24,18 @@ internal class BlockTerminalFeedbackDialog(project: Project, forTest: Boolean) :
override val mySystemInfoData: BlockTerminalUsageData by lazy {
val usageStorage = TerminalUsageLocalStorage.getInstance()
val rawMostUsedShell = usageStorage.mostUsedShell
val mostUsedShell = if (rawMostUsedShell == null && forTest) {
thisLogger().warn("No information about most used shell, because no commands were executed in the terminal")
"none"
}
else {
// It is guaranteed to be not null if it is not a test because of the check in BlockTerminalSurveyConfig.checkExtraConditionSatisfied
rawMostUsedShell!!
}
BlockTerminalUsageData(
mostUsedShell = usageStorage.mostUsedShell,
mostUsedShell = mostUsedShell,
executedCommandsNumber = usageStorage.executedCommandsNumber,
feedbackMoment = getFeedbackMoment(project),
systemInfo = CommonFeedbackSystemData.getCurrentData()