Skip to content

Commit 6b5f024

Browse files
authored
Ban Gson (#4139)
Gson is currently on the classpath, but the rest of the repo uses Jackson ObjectMapper. Gson is also in maintenance mode.
1 parent a990210 commit 6b5f024

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

detekt-rules/src/software/aws/toolkits/gradle/detekt/rules/BannedImportsRule.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ class BannedImportsRule : Rule() {
6969
)
7070
)
7171
}
72+
73+
if (importedFqName == "com.google.gson.Gson") {
74+
report(
75+
CodeSmell(
76+
issue,
77+
Entity.from(element),
78+
message = "Use jacksonObjectMapper() insted of Gson"
79+
)
80+
)
81+
}
7282
}
7383
}
7484
}

detekt-rules/tst/software/aws/toolkits/gradle/detekt/rules/BannedImportsRuleTest.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ class BannedImportsRuleTest {
2424
.matches { it.id == "BannedImports" && it.message == "Use AssertJ instead of Hamcrest assertions" }
2525
}
2626

27+
@Test
28+
fun `Importing Gson fails`() {
29+
assertThat(rule.lint("import com.google.gson.Gson"))
30+
.singleElement()
31+
.matches { it.id == "BannedImports" && it.message == "Use jacksonObjectMapper() insted of Gson" }
32+
}
33+
2734
@Test
2835
fun `Importing Kotlin test assert fails`() {
2936
assertThat(rule.lint("import kotlin.test.assertTrue"))

jetbrains-core/tst/software/aws/toolkits/jetbrains/services/codewhisperer/CodeWhispererTelemetryTest.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
package software.aws.toolkits.jetbrains.services.codewhisperer
55

6-
import com.google.gson.Gson
6+
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
77
import com.intellij.openapi.application.ApplicationManager
88
import com.intellij.openapi.command.WriteCommandAction
99
import com.intellij.openapi.editor.Editor
@@ -379,14 +379,15 @@ class CodeWhispererTelemetryTest : CodeWhispererTestBase() {
379379
fun `test user Decision events record CodeWhisperer reference info`() {
380380
val userGroup = CodeWhispererUserGroupSettings.getInstance().getUserGroup()
381381
withCodeWhispererServiceInvokedAndWait {}
382+
val mapper = jacksonObjectMapper()
382383
argumentCaptor<MetricEvent>().apply {
383384
verify(batcher, atLeastOnce()).enqueue(capture())
384385
pythonResponse.completions().forEach {
385386
assertEventsContainsFieldsAndCount(
386387
allValues,
387388
userDecision,
388389
1,
389-
"codewhispererSuggestionReferences" to Gson().toJson(it.references().map { ref -> ref.licenseName() }.toSet()),
390+
"codewhispererSuggestionReferences" to mapper.writeValueAsString(it.references().map { ref -> ref.licenseName() }.toSet()),
390391
"codewhispererSuggestionReferenceCount" to it.references().size.toString(),
391392
"codewhispererUserGroup" to userGroup.name,
392393
atLeast = true

0 commit comments

Comments
 (0)