Skip to content

refactor: extract duplicated string literals in KapperImpl#328

Merged
driessamyn merged 1 commit into
mainfrom
refactor/sonar-code-quality
Mar 28, 2026
Merged

refactor: extract duplicated string literals in KapperImpl#328
driessamyn merged 1 commit into
mainfrom
refactor/sonar-code-quality

Conversation

@driessamyn
Copy link
Copy Markdown
Owner

@driessamyn driessamyn commented Mar 28, 2026

Summary

  • Extract duplicated string literals in KapperImpl to companion object constants
  • Fixes SonarCloud S1192 (HIGH) — "SQL query cannot be empty or blank" and "Executing prepared statement: {}" were each duplicated 3 times

Sonar issues addressed

Rule Severity Description
S1192 HIGH Duplicated string literal "SQL query cannot be empty or blank" (3 occurrences)
S1192 HIGH Duplicated string literal "Executing prepared statement: {}" (3 occurrences)

Sonar issues skipped

Rule Severity Reason
S6518 MEDIUM MapperRegistry.get() is not an operator fun, so indexed accessor syntax ([]) would not compile

Test plan

  • ./gradlew :kapper:test passes

Summary by CodeRabbit

  • Chores
    • Internal code improvements for maintainability and consistency.

Extract repeated string literals to companion object constants to
satisfy SonarCloud rules S1192. Skipped S6518 (indexed accessor in
coroutines) as MapperRegistry.get() is not an operator function.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 28, 2026

📝 Walkthrough

Walkthrough

Refactoring effort that extracts two repeated string literals (SQL_BLANK_ERROR and EXECUTING_STMT_LOG) into companion object constants within KapperImpl.kt, replacing their inline usage across query execution and validation methods.

Changes

Cohort / File(s) Summary
String literal consolidation
core/src/main/kotlin/net/samyn/kapper/internal/KapperImpl.kt
Added two private const values (SQL_BLANK_ERROR, EXECUTING_STMT_LOG) in companion object and replaced inline string literals with constant references in error messages and debug logging across multiple execute/executeReturning methods.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐰 Constants neat, no strings astray,
Magic numbers tucked away,
Clarity blooms in code so bright,
One small hop, one perfect sight!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: extracting duplicated string literals in KapperImpl to constants, which is the primary objective of the pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/sonar-code-quality

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
core/src/main/kotlin/net/samyn/kapper/internal/KapperImpl.kt (1)

116-117: Optional follow-up: extract duplicated execution failure message too.

"Failed to execute statement: $sql" is still duplicated in two catch blocks. Consider a small helper or shared constant pattern for consistency with this refactor.

Also applies to: 147-148

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@core/src/main/kotlin/net/samyn/kapper/internal/KapperImpl.kt` around lines
116 - 117, The two catch blocks in KapperImpl are duplicating the literal
"Failed to execute statement: $sql"; extract that into a single reusable element
(either a private helper method like buildExecuteFailMessage(sql: String):
String or a private constant pattern plus String.format) and replace both
occurrences so both catch blocks call the helper (and keep the existing
logger.warn(message, e) usage); update any other identical occurrences (e.g.,
the ones around the existing logger.warn(it, e) calls) to use the same helper
for consistency.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@core/src/main/kotlin/net/samyn/kapper/internal/KapperImpl.kt`:
- Around line 116-117: The two catch blocks in KapperImpl are duplicating the
literal "Failed to execute statement: $sql"; extract that into a single reusable
element (either a private helper method like buildExecuteFailMessage(sql:
String): String or a private constant pattern plus String.format) and replace
both occurrences so both catch blocks call the helper (and keep the existing
logger.warn(message, e) usage); update any other identical occurrences (e.g.,
the ones around the existing logger.warn(it, e) calls) to use the same helper
for consistency.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f1b2694e-0c61-4346-a8ec-681304233741

📥 Commits

Reviewing files that changed from the base of the PR and between 1d8d836 and f3e47bb.

📒 Files selected for processing (1)
  • core/src/main/kotlin/net/samyn/kapper/internal/KapperImpl.kt

@github-actions
Copy link
Copy Markdown

Unit Tests

 62 files  ±0   62 suites  ±0   3m 12s ⏱️ +10s
562 tests ±0  562 ✅ ±0  0 💤 ±0  0 ❌ ±0 
578 runs  ±0  578 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit f3e47bb. ± Comparison against base commit 1d8d836.

This pull request removes 39 and adds 39 tests. Note that renamed tests count towards both.
net.samyn.kapper.internal.automapper.SQLTypesConverterTest ‑ [10] LONGVARCHAR, "LONGVARCHAR", net.samyn.kapper.internal.automapper.SQLTypesConverterTest$Companion$$Lambda$1119/0x00007fb62c56d5d8@5062dc98
net.samyn.kapper.internal.automapper.SQLTypesConverterTest ‑ [11] NCHAR, "NCHAR", net.samyn.kapper.internal.automapper.SQLTypesConverterTest$Companion$$Lambda$1120/0x00007fb62c56d7f8@11562e10
net.samyn.kapper.internal.automapper.SQLTypesConverterTest ‑ [12] INSTANT, net.samyn.kapper.internal.automapper.SQLTypesConverterTest$Companion$$Lambda$966/0x00007fb62c535770@3bb6ed70
net.samyn.kapper.internal.automapper.SQLTypesConverterTest ‑ [12] NCLOB, "NCLOB", net.samyn.kapper.internal.automapper.SQLTypesConverterTest$Companion$$Lambda$1121/0x00007fb62c56da18@462b3f56
net.samyn.kapper.internal.automapper.SQLTypesConverterTest ‑ [13] DATE, net.samyn.kapper.internal.automapper.SQLTypesConverterTest$Companion$$Lambda$967/0x00007fb62c535990@429cbabf
net.samyn.kapper.internal.automapper.SQLTypesConverterTest ‑ [13] NVARCHAR, "NVARCHAR", net.samyn.kapper.internal.automapper.SQLTypesConverterTest$Companion$$Lambda$1122/0x00007fb62c56dc38@3f00dc90
net.samyn.kapper.internal.automapper.SQLTypesConverterTest ‑ [14] LOCALDATE, net.samyn.kapper.internal.automapper.SQLTypesConverterTest$Companion$$Lambda$968/0x00007fb62c535bb0@188c17f0
net.samyn.kapper.internal.automapper.SQLTypesConverterTest ‑ [14] ROWID, "ROWID", net.samyn.kapper.internal.automapper.SQLTypesConverterTest$Companion$$Lambda$1123/0x00007fb62c56de58@5529d40
net.samyn.kapper.internal.automapper.SQLTypesConverterTest ‑ [15] LOCALDATETIME, net.samyn.kapper.internal.automapper.SQLTypesConverterTest$Companion$$Lambda$969/0x00007fb62c535dd0@717c56fc
net.samyn.kapper.internal.automapper.SQLTypesConverterTest ‑ [15] SQLXML, "SQLXML", net.samyn.kapper.internal.automapper.SQLTypesConverterTest$Companion$$Lambda$1124/0x00007fb62c56e078@50bd846c
…
net.samyn.kapper.internal.automapper.SQLTypesConverterTest ‑ [10] LONGVARCHAR, "LONGVARCHAR", net.samyn.kapper.internal.automapper.SQLTypesConverterTest$Companion$$Lambda$1154/0x00007fcf3857e0a0@1c8de050
net.samyn.kapper.internal.automapper.SQLTypesConverterTest ‑ [11] NCHAR, "NCHAR", net.samyn.kapper.internal.automapper.SQLTypesConverterTest$Companion$$Lambda$1155/0x00007fcf3857e2c0@6a54a4bc
net.samyn.kapper.internal.automapper.SQLTypesConverterTest ‑ [12] INSTANT, net.samyn.kapper.internal.automapper.SQLTypesConverterTest$Companion$$Lambda$991/0x00007fcf385454c0@505e85b9
net.samyn.kapper.internal.automapper.SQLTypesConverterTest ‑ [12] NCLOB, "NCLOB", net.samyn.kapper.internal.automapper.SQLTypesConverterTest$Companion$$Lambda$1156/0x00007fcf3857e4e0@6b9dad70
net.samyn.kapper.internal.automapper.SQLTypesConverterTest ‑ [13] DATE, net.samyn.kapper.internal.automapper.SQLTypesConverterTest$Companion$$Lambda$992/0x00007fcf385456e0@14ca0a3c
net.samyn.kapper.internal.automapper.SQLTypesConverterTest ‑ [13] NVARCHAR, "NVARCHAR", net.samyn.kapper.internal.automapper.SQLTypesConverterTest$Companion$$Lambda$1157/0x00007fcf3857e700@195c6488
net.samyn.kapper.internal.automapper.SQLTypesConverterTest ‑ [14] LOCALDATE, net.samyn.kapper.internal.automapper.SQLTypesConverterTest$Companion$$Lambda$993/0x00007fcf38545900@400d5258
net.samyn.kapper.internal.automapper.SQLTypesConverterTest ‑ [14] ROWID, "ROWID", net.samyn.kapper.internal.automapper.SQLTypesConverterTest$Companion$$Lambda$1158/0x00007fcf3857e920@6e57cec7
net.samyn.kapper.internal.automapper.SQLTypesConverterTest ‑ [15] LOCALDATETIME, net.samyn.kapper.internal.automapper.SQLTypesConverterTest$Companion$$Lambda$994/0x00007fcf38545b20@4c78fd6f
net.samyn.kapper.internal.automapper.SQLTypesConverterTest ‑ [15] SQLXML, "SQLXML", net.samyn.kapper.internal.automapper.SQLTypesConverterTest$Companion$$Lambda$1159/0x00007fcf3857eb40@5e748cd3
…

@github-actions
Copy link
Copy Markdown

SQLITE Integration Tests

12 files  ±0  12 suites  ±0   23s ⏱️ -3s
55 tests ±0  50 ✅ ±0  5 💤 ±0  0 ❌ ±0 
85 runs  ±0  80 ✅ ±0  5 💤 ±0  0 ❌ ±0 

Results for commit f3e47bb. ± Comparison against base commit 1d8d836.

@github-actions
Copy link
Copy Markdown

DUCKDB Integration Tests

12 files  ±0  12 suites  ±0   24s ⏱️ -2s
55 tests ±0  55 ✅ ±0  0 💤 ±0  0 ❌ ±0 
85 runs  ±0  85 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit f3e47bb. ± Comparison against base commit 1d8d836.

@github-actions
Copy link
Copy Markdown

POSTGRESQL Integration Tests

12 files  ±0  12 suites  ±0   26s ⏱️ ±0s
55 tests ±0  55 ✅ ±0  0 💤 ±0  0 ❌ ±0 
85 runs  ±0  85 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit f3e47bb. ± Comparison against base commit 1d8d836.

@github-actions
Copy link
Copy Markdown

MSSQLSERVER Integration Tests

12 files  ±0  12 suites  ±0   43s ⏱️ -1s
55 tests ±0  46 ✅ ±0  9 💤 ±0  0 ❌ ±0 
85 runs  ±0  76 ✅ ±0  9 💤 ±0  0 ❌ ±0 

Results for commit f3e47bb. ± Comparison against base commit 1d8d836.

@github-actions
Copy link
Copy Markdown

MYSQL Integration Tests

12 files  ±0  12 suites  ±0   48s ⏱️ +4s
55 tests ±0  46 ✅ ±0  9 💤 ±0  0 ❌ ±0 
85 runs  ±0  76 ✅ ±0  9 💤 ±0  0 ❌ ±0 

Results for commit f3e47bb. ± Comparison against base commit 1d8d836.

@github-actions
Copy link
Copy Markdown

ORACLE Integration Tests

12 files  ±0  12 suites  ±0   1m 14s ⏱️ +2s
55 tests ±0  46 ✅ ±0  9 💤 ±0  0 ❌ ±0 
85 runs  ±0  76 ✅ ±0  9 💤 ±0  0 ❌ ±0 

Results for commit f3e47bb. ± Comparison against base commit 1d8d836.

@github-actions
Copy link
Copy Markdown

Code Coverage

Metric Coverage
Line N/A
Branch N/A
Instruction N/A

Updated for commit f3e47bb

@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@driessamyn driessamyn merged commit 5c105e1 into main Mar 28, 2026
21 checks passed
@driessamyn driessamyn deleted the refactor/sonar-code-quality branch March 28, 2026 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant