From f6ccf201f47c1cc5466a0b7790d43cc59f9b8d09 Mon Sep 17 00:00:00 2001 From: Carl-Robert Linnupuu Date: Sun, 8 Jun 2025 09:12:51 +0100 Subject: [PATCH] fix: NPE (fixes #1046) --- .../codegpt/conversations/ConversationService.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/ee/carlrobert/codegpt/conversations/ConversationService.java b/src/main/java/ee/carlrobert/codegpt/conversations/ConversationService.java index c58cca36..a6e2f080 100644 --- a/src/main/java/ee/carlrobert/codegpt/conversations/ConversationService.java +++ b/src/main/java/ee/carlrobert/codegpt/conversations/ConversationService.java @@ -2,6 +2,7 @@ package ee.carlrobert.codegpt.conversations; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.Service; +import com.intellij.openapi.diagnostic.Logger; import ee.carlrobert.codegpt.completions.ChatCompletionParameters; import ee.carlrobert.codegpt.conversations.message.Message; import ee.carlrobert.codegpt.settings.GeneralSettings; @@ -24,6 +25,8 @@ import org.jetbrains.annotations.NotNull; @Service public final class ConversationService { + private static final Logger LOG = Logger.getInstance(ConversationService.class); + private final ConversationsState conversationState = ConversationsState.getInstance(); private ConversationService() { @@ -111,7 +114,13 @@ public final class ConversationService { } public Conversation startConversation() { - var completionCode = GeneralSettings.getSelectedService().getCompletionCode(); + var selectedService = GeneralSettings.getSelectedService(); + if (selectedService == null) { + LOG.warn("Selected service is not defined, falling back to ProxyAI."); + selectedService = ServiceType.CODEGPT; + } + + var completionCode = selectedService.getCompletionCode(); var conversation = createConversation(completionCode); conversationState.setCurrentConversation(conversation); addConversation(conversation);