Skip to content

FileName/FileFormat domain primitive; fix new-code Sonar findings - #364

Merged
dfa1 merged 1 commit into
mainfrom
refactor/file-name-primitive-and-sonar
Sep 3, 2026
Merged

FileName/FileFormat domain primitive; fix new-code Sonar findings#364
dfa1 merged 1 commit into
mainfrom
refactor/file-name-primitive-and-sonar

Conversation

@dfa1

@dfa1 dfa1 commented Sep 3, 2026

Copy link
Copy Markdown
Owner

Summary

  • FileFormat/FileName (package-private, cli module): a small domain primitive centralizing extension parsing/swapping (.csv/.parquet/.vortex), replacing scattered endsWith(".xxx") checks and hand-counted substring(0, name.length() - N) suffix strips across ImportCommand/ExportCommand. Behavior-preserving — no functional change.
  • Fixes all 17 SonarCloud findings currently in the new-code period (sinceLeakPeriod=true), triaged individually — see commit message for the per-finding reasoning. Highlights:
    • ImportCommand: .parquet literal duplication resolved as a side effect of the refactor; a temp-file-permissions fix (S5443, CRITICAL) restricts the CSV→Parquet chain's scratch file to owner-only on POSIX, with a Windows-safe fallback.
    • CsvImporter: split an over-15-cognitive-complexity method into three smaller ones (S3776).
    • ParquetExporter: switched ignored pattern-variable bindings to the JDK unnamed _, matching this codebase's own established convention elsewhere.
    • Three test files: lambda/assertion cleanups (S5778, S5838).

Test plan

  • ./mvnw verify -pl cli -am / -pl csv -am / -pl parquet -am / -pl writer -am — all green, including a new FileNameTest
  • ./mvnw verify — full reactor build, all modules green
  • ./mvnw verify -pl integration -am -Dit.test=DocsConsistencyTest — living-docs claims still resolve

🤖 Generated with Claude Code

https://claude.ai/code/session_01LjU7zWghUiJauRxK58nyUs

…ar findings

FileFormat (CSV/PARQUET/VORTEX) + FileName wrap the extension parsing
and swapping import/export both need, replacing a scattered set of
endsWith(".xxx") checks and hand-counted substring(0, name.length() - N)
suffix strips duplicated across ImportCommand and ExportCommand.

Also fixes the 17 SonarCloud findings in the new-code period
(sinceLeakPeriod=true), triaged individually:

- ImportCommand: the .parquet literal duplication (S1192) is resolved
  as a side effect of the FileName refactor above. Two ternaries moved
  inside their single Path.of(...) call (S9358). The CSV-to-Parquet
  temp file now gets owner-only POSIX permissions (rw-------) via
  FileAttribute, since the system temp directory is commonly
  world-writable (S5443, CRITICAL) -- falls back to the plain overload
  on Windows, where FileAttribute-based permissions aren't supported.
- CsvImporter: split the 17-cognitive-complexity private importCsv
  helper into readFirstChunk/writeFirstChunk/streamRemainingChunks,
  each well under the 15 threshold (S3776).
- ParquetExporter: switched `case DType.Xxx ignored ->` to the JDK
  unnamed-variable `_`, matching the convention CsvImporter's own
  switches already use elsewhere in this codebase -- `_` is exempt from
  the unused-variable rule by design, `ignored` isn't (S1481 x7).
- ParquetExporterTest: extracted an inline `new DType.Primitive(...)`
  out of an assertThatThrownBy lambda into a `// Given` variable, so
  the lambda contains exactly one invocation that can throw (S5778);
  three isEqualTo(0) assertions switched to isZero() (S5838 x3).
- ZstdEncodingEncoderTest: same S5778 shape (EncodeTestHelper.testCtx()
  invocation extracted out of the lambda), from a slightly earlier
  commit still inside the leak period.

Review caught two real regressions in the FileName refactor itself,
both fixed:
- FileName#withFormat stripped ANY known extension before appending
  the target's, including one already equal to the target -- so
  deriving a default output name from an input already in that format
  (e.g. `import data.vortex` with no output arg) returned the input's
  own name back. import/export would then open that path for writing
  while still reading it as the source, truncating it. Fixed by only
  stripping a *different* known extension; added a regression test
  (withFormat_alreadyTargetFormat_appendsRatherThanReturningSameName).
- CsvImporter's FirstChunk record had its rows list mutated (.clear())
  after construction, fighting the immutable-value-object expectation
  records set up. Restructured so importCsv stops referencing the
  FirstChunk (and thus its buffered rows) after handing it to
  writeFirstChunk, instead of mutating it -- the streaming loop that
  follows still doesn't retain the buffered rows, without needing a
  mutation to make that true. Also dropped the redundant chunkSize
  parameter threaded through two helpers when it was always just
  options.chunkSize().

Also converted two FileNameTest cases to // Given / // When / // Then
(they'd collapsed to a single comment with stacked assertions).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LjU7zWghUiJauRxK58nyUs
@dfa1
dfa1 force-pushed the refactor/file-name-primitive-and-sonar branch from 6340f35 to fa7fa9d Compare September 3, 2026 16:56
@dfa1
dfa1 merged commit 3dea69b into main Sep 3, 2026
6 checks passed
@dfa1
dfa1 deleted the refactor/file-name-primitive-and-sonar branch September 3, 2026 17:00
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