Skip to content

Commit 2174ed7

Browse files
committed
GH-310 Fixed NullPointerException when zowe.config is empty
Signed-off-by: Katsiaryna Tsytsenia <[email protected]>
1 parent e9eca9a commit 2174ed7

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/main/kotlin/org/zowe/kotlinsdk/zowe/config/utils.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,10 @@ private fun formProfiles (profiles: Map<String, ZoweConfigProfile>?) {
8787
* Parses JSON string to [ZoweConfig] object model.
8888
* @param configString JSON string with zowe config.
8989
* @return [ZoweConfig] object model.
90+
* @throws [com.google.gson.JsonSyntaxException] and NullPointerException in case of empty file
9091
*/
9192
fun parseConfigJson(configString: String): ZoweConfig {
92-
val zoweConfig = Gson().fromJson(configString, ZoweConfig::class.java)
93+
val zoweConfig = Gson().fromJson(configString, ZoweConfig::class.java) ?: throw NullPointerException()
9394
zoweConfig.zosmfProfile = zoweConfig.profile(zoweConfig.defaults["zosmf"])
9495
formProfiles(zoweConfig.profiles)
9596
return zoweConfig
@@ -99,6 +100,7 @@ fun parseConfigJson(configString: String): ZoweConfig {
99100
* Reads input stream and parse it to ZoweConfig object model.
100101
* @param inputStream - stream with json string of zowe config.
101102
* @return ZoweConfig object model.
103+
* @throws [com.google.gson.JsonSyntaxException] and NullPointerException in case of empty file
102104
*/
103105
fun parseConfigJson (inputStream: InputStream): ZoweConfig = parseConfigJson(String(inputStream.readBytes()))
104106

src/test/kotlin/org/zowe/kotlinsdk/zowe/ZoweConfigParsingTest.kt

+5
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ class ZoweConfigParsingTest: ZoweConfigTestBase() {
6868
checkZoweConfig(zoweConfig)
6969
}
7070

71+
@Test
72+
fun testParsingEmptyJsonString() {
73+
Assertions.assertThrows(NullPointerException::class.java){ parseConfigJson("") }
74+
}
75+
7176
@Test
7277
fun testZOSConnection() {
7378
val zoweConfig = parseConfigJson(streamConfigJson)

0 commit comments

Comments
 (0)