Skip to content

Commit

Permalink
fix: handle null values (#583)
Browse files Browse the repository at this point in the history
* fix: handle null values

* docs: CHANGELOG.md

* fix: service definition

* fix: NPE

* fix: NPE

* fix: remove obsolete feature flag
  • Loading branch information
bastiandoetsch authored Aug 27, 2024
1 parent 8589904 commit a81f143
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 28 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
- All HTTP communications now goes through language server
- Removed Snyk Advisor
- Removed Amplitude integration
- Handle exception
- Do not excessively spawn CLIs
- Remove UI freezes caused by annotator
- Limit navigation functions to only use UI thread when needed

## [2.8.11]
### Added
Expand Down
43 changes: 23 additions & 20 deletions src/main/kotlin/snyk/common/lsp/SnykLanguageClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class SnykLanguageClient :
}
}

fun updateCache(
private fun updateCache(
project: Project,
filePath: String,
diagnosticsParams: PublishDiagnosticsParams,
Expand All @@ -127,12 +127,14 @@ class SnykLanguageClient :
return
}

val issueList = diagnosticsParams.diagnostics.stream().map {
val issue = gson.fromJson(it.data.toString(), ScanIssue::class.java)
// load textrange for issue so it doesn't happen in UI thread
issue.textRange
issue
}.toList()
val issueList = diagnosticsParams.diagnostics
.filter { it.data != null }
.map {
val issue = gson.fromJson(it.data.toString(), ScanIssue::class.java)
// load textrange for issue so it doesn't happen in UI thread
issue.textRange
issue
}.toList()

when (product) {
LsProductConstants.OpenSource.value -> {
Expand Down Expand Up @@ -424,26 +426,27 @@ class SnykLanguageClient :
token: String,
workDoneProgressNotification: WorkDoneProgressNotification,
) {
logger.debug("###### Received progress report notification for token: $token")
val indicator = progresses.getIfPresent(token)!!
val report: WorkDoneProgressReport = workDoneProgressNotification as WorkDoneProgressReport
logger.debug("###### Token: $token, progress: ${report.percentage}%, message: ${report.message}")

indicator.text = report.message
indicator.isIndeterminate = false
indicator.fraction = report.percentage / 100.0
logger.debug("Received progress report notification for token: $token")
progresses.getIfPresent(token)?.let {
val report: WorkDoneProgressReport = workDoneProgressNotification as WorkDoneProgressReport
logger.debug("Token: $token, progress: ${report.percentage}%, message: ${report.message}")
it.text = report.message
it.isIndeterminate = false
it.fraction = report.percentage / 100.0
}
return
}

private fun progressEnd(
token: String,
workDoneProgressNotification: WorkDoneProgressNotification,
) {
logger.debug("###### Received progress end notification for token: $token")
val indicator = progresses.getIfPresent(token)!!
val workDoneProgressEnd = workDoneProgressNotification as WorkDoneProgressEnd
indicator.text = workDoneProgressEnd.message
progresses.invalidate(token)
logger.debug("Received progress end notification for token: $token")
progresses.getIfPresent(token)?.let {
val workDoneProgressEnd = workDoneProgressNotification as WorkDoneProgressEnd
it.text = workDoneProgressEnd.message
progresses.invalidate(token)
}
return
}

Expand Down
7 changes: 4 additions & 3 deletions src/main/kotlin/snyk/container/ContainerService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import snyk.common.SnykError

private val LOG = logger<ContainerService>()

@Service
@Service(Service.Level.PROJECT)
class ContainerService(project: Project) : CliAdapter<ContainerIssuesForImage, ContainerResult>(
project = project
) {
Expand Down Expand Up @@ -138,17 +138,18 @@ class ContainerService(project: Project) : CliAdapter<ContainerIssuesForImage, C
override fun getProductResult(cliIssues: List<ContainerIssuesForImage>?, snykErrors: List<SnykError>): ContainerResult =
ContainerResult(cliIssues, snykErrors)

@Suppress("UNNECESSARY_SAFE_CALL")
override fun sanitizeCliIssues(cliIssues: ContainerIssuesForImage): ContainerIssuesForImage =
// .copy() will check nullability of fields
cliIssues.copy(
vulnerabilities = cliIssues.vulnerabilities.map { containerIssue ->
vulnerabilities = cliIssues?.vulnerabilities?.map { containerIssue ->
containerIssue.copy(
identifiers = containerIssue.identifiers?.copy(),
// @Expose fields are `null` after Gson parser, so explicit init needed
obsolete = false,
ignored = false
)
},
}.orEmpty(),
workloadImages = emptyList()
)

Expand Down
5 changes: 0 additions & 5 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@
defaultValue="720000"
description="Snyk timeout (milliseconds) to wait for results during scan"/>

<registryKey key="snyk.preview.snyk.code.ls.enabled"
defaultValue="false"
description="Preview: Use language server as source for Snyk Code findings."
restartRequired="true"/>

<registryKey key="snyk.preview.snyk.oss.ls.enabled"
defaultValue="false"
description="Preview: Use language server as source for Snyk OSS findings."
Expand Down

0 comments on commit a81f143

Please sign in to comment.