Skip to content

fix(snowflake): null-safe metadata compare in column-type build - #2001

Merged
openai0229 merged 5 commits into
OtterMind:mainfrom
Aias00:fix/1998-snowflake-npe
Jul 24, 2026
Merged

openai0229 merged 5 commits into
OtterMind:mainfrom
Aias00:fix/1998-snowflake-npe

Conversation

@Aias00

@Aias00 Aias00 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Related issue

Closes #1998

Summary

SnowflakeColumnTypeEnum.buildDataType and buildNullable compared
Integer-typed column metadata (columnSize, decimalDigits,
nullable) using .equals(). These fields are boxed Integer and are
null when the driver omits metadata — the same null-metadata scenario
already handled in DBStructUtils (#1968) but not applied here.

  • buildDataType (lines 128–129) dereferenced
    column.getOldColumn().getColumnSize() / getDecimalDigits() → NPE on MODIFY.
  • buildNullable (line 174) called column.getNullable().equals(...)
    before its own getNullable() != null guard (line 175) → NPE on MODIFY
    when nullable metadata is missing.

Switched both to Objects.equals(...), and added a regression test
(SnowflakeColumnTypeEnumTest) that constructs a MODIFY column with null
Integer metadata on both the current and old column and asserts
buildCreateColumnSql no longer throws.

Affected surfaces

  • Frontend / Web
  • Backend / API / Storage
  • Database plugin / Driver
  • JCEF / Desktop packaging
  • CI / Build / Release
  • Documentation only

Verification

  • Commands and results:
    mvn -B -f chat2db-community-server/pom.xml \
      -pl chat2db-community-plugins/chat2db-community-snowflake -am \
      -Dmaven.test.skip=false -DskipTests=false \
      -Dtest=ai.chat2db.plugin.snowflake.enums.type.SnowflakeColumnTypeEnumTest \
      -Dsurefire.failIfNoSpecifiedTests=false -Dmaven.test.failure.ignore=false test
    
    Tests run: 2, Failures: 0, Errors: 0, Skipped: 0; reactor BUILD SUCCESS.
  • Manual verification: N/A (no Snowflake instance available locally); the test reproduces the previously-throwing MODIFY path with null metadata.
  • UI evidence: N/A

Risk and compatibility

  • Public API or stored data: N/A — only changes generated ALTER text.
  • Database or driver compatibility: Snowflake MODIFY-column generation no longer NPEs on columns whose size/scale/nullable metadata is absent; behavior for populated metadata is unchanged (Objects.equals matches .equals semantics for non-null).
  • Network, privacy, or security: N/A.
  • Community / Local / Pro boundary: N/A.
  • Backward compatibility: Only fixes a crash; no API change.

Reviewer map

  • Start here: SnowflakeColumnTypeEnum.java lines 128–130 and 175 — .equalsObjects.equals; new import java.util.Objects.
  • Failure condition: MODIFY-column ALTER generation throws NPE when column size/scale/nullable metadata is missing.
  • Rollback or disable path: Revert this single commit; the new test documents the expected behavior.

Contributor declaration

  • I linked the Issue that defines this change.
  • I tested the affected behavior and reported the actual results above.
  • I did not include credentials, private data, or generated build output.
  • I disclosed substantial AI assistance below, or this PR contains no substantial AI-generated code.

AI assistance: The fix, test, verification, and PR description were produced with Claude Code assistance.

buildDataType and buildNullable called .equals() on Integer-typed
column metadata (columnSize / decimalDigits / nullable) that can be
null when the driver omits it, throwing NullPointerException during
MODIFY-column ALTER generation. The null guard on nullable ran after
the dereference. Use Objects.equals and the same null-metadata
handling as DBStructUtils (OtterMind#1968). Adds a regression test.

Fixes OtterMind#1998

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 24, 2026 05:11
@Aias00
Aias00 requested a review from openai0229 as a code owner July 24, 2026 05:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@openai0229 openai0229 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed and updated. The null-safe size/scale comparisons are correct. I also tightened the MODIFY nullable path so missing metadata cannot be misinterpreted as a NOT NULL change, and added a regression assertion for the generated SQL. Targeted Snowflake tests pass locally.

@openai0229
openai0229 merged commit 2f0e510 into OtterMind:main Jul 24, 2026
16 checks passed
@openai0229 openai0229 moved this from In Review to Done in Chat2DB Community Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Snowflake: NPE in MODIFY column-type generation when metadata is null

3 participants