Skip to content

Commit ece8105

Browse files
jimonthebarnyusufugurozbek
authored andcommitted
Replace port via data class property instead of string replacement
1 parent b0729a8 commit ece8105

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/main/kotlin/com/github/yusufugurozbek/testcontainers/port/updater/impl/DataSourceUpdaterImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class DataSourceUpdaterImpl(private var project: Project) : DataSourceUpdater {
3535
private fun getLogMessage(logEntryText: String): String {
3636
if (settingsState.loggingFormat == LoggingFormat.JSON && logEntryText.contains(settingsState.logEntryPrefix)) {
3737
try {
38-
return Json.parseToJsonElement(logEntryText).jsonObject["message"]!!.jsonPrimitive.content
38+
return Json.parseToJsonElement(logEntryText).jsonObject["message"]?.jsonPrimitive?.content ?: ""
3939
} catch (e: Exception) {
4040
thisLogger().warn("JSON log message cannot be extracted", e)
4141
}
@@ -53,7 +53,7 @@ class DataSourceUpdaterImpl(private var project: Project) : DataSourceUpdater {
5353
val isUpdatable = dataSourceUrl.matches(logEntryDataSourceUrl, settingsState.matchMode)
5454

5555
if (isUpdatable) {
56-
val newUrl = dataSourceUrl.toString().replace(dataSourceUrl.port, logEntryDataSourceUrl.port)
56+
val newUrl = dataSourceUrl.copy(port = logEntryDataSourceUrl.port).toString()
5757
localDataSource.url = newUrl
5858
if (settingsState.isNotificationsEnabled) {
5959
TpuNotifier.notify(project, "Updated data source URL: $newUrl")

0 commit comments

Comments
 (0)