Skip to content

Commit

Permalink
GH-310 Fixed NullPointerException when zowe.config is empty
Browse files Browse the repository at this point in the history
Signed-off-by: Katsiaryna Tsytsenia <[email protected]>
  • Loading branch information
ktsytsen committed Feb 14, 2025
1 parent 2866c9d commit 47b7795
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,13 @@ class ZOSMFConnectionConfigurable : BoundSearchableConfigurable("z/OSMF Connecti

val zoweConfig = try {
parseConfigJson(configFile.inputStream)
} catch (e: JsonSyntaxException) {
NotificationsService.errorNotification(
e,
project = DataManager.getInstance().getDataContext(panel).getData(PlatformDataKeys.PROJECT),
custTitle = "Error with Zowe config file"
)
} catch (e: Exception) {
if (e is JsonSyntaxException)
NotificationsService.errorNotification(
e,
project = DataManager.getInstance().getDataContext(panel).getData(PlatformDataKeys.PROJECT),
custTitle = "Error with Zowe config file"
)
return
}
zoweConfig.extractSecureProperties(configFile.path.split("/").toTypedArray())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package org.zowe.explorer.zowe.actions

import com.intellij.icons.AllIcons
import com.google.gson.JsonSyntaxException
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
Expand Down Expand Up @@ -94,7 +93,7 @@ class UpdateZoweConfigAction : DumbAwareAction() {
zoweConfigService.globalZoweConfig = parseConfigJson(editor.document.text)
zoweConfigService.globalZoweConfig?.extractSecureProperties(vFile.path.split("/").toTypedArray())
}
} catch (ex: JsonSyntaxException) {
} catch (ex: Exception) {
e.presentation.isEnabledAndVisible = false
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ class ZoweConfigServiceImpl(override val myProject: Project) : ZoweConfigService
}
}
} catch (e: Exception) {
NotificationsService.errorNotification(e, project = myProject, custTitle="Error with Zowe config file")
//parseConfigJson returns NullPointerException in case of empty file
if (e !is NullPointerException)
NotificationsService.errorNotification(e, project = myProject, custTitle = "Error with Zowe config file")
return null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.vfs.VirtualFileManager
import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldContain
import io.kotest.matchers.types.shouldNotBeSameInstanceAs
import io.mockk.*
import org.zowe.explorer.common.ui.DialogMode
import org.zowe.explorer.common.ui.ValidatingTableView
Expand Down Expand Up @@ -207,13 +208,31 @@ class ZOSMFConnectionConfigurableTest : WithApplicationShouldSpec({
try {
it.call(zOSMFConnectionConfigurableMock, state)
} catch (t: Throwable) {
println("ghjkk")
t.cause.toString().shouldContain("Zowe config file not found")
}
}
notified shouldBe true
}

every { vfMock.inputStream } answers {
isInputStreamCalled = true
"".toByteArray().inputStream()
}

should("updateZoweConfigIfNeeded empty zowe config file") {
zOSMFConnectionConfigurableMock::class.declaredMemberFunctions.find { it.name == "updateZoweConfigIfNeeded" }
?.let {
it.isAccessible = true
try {
it.call(zOSMFConnectionConfigurableMock, state)
} catch (t: Throwable) {
t shouldNotBeSameInstanceAs NullPointerException()
}
}
notified shouldBe false
isInputStreamCalled shouldBe true
}

every { vfMock.inputStream } answers {
isInputStreamCalled = true
val fileCont = "{\n" +
Expand Down

0 comments on commit 47b7795

Please sign in to comment.