fix: fix unclosed literal error for consecutive backslashes by rayudu3745 · Pull Request #4387 · googleapis/java-spanner · GitHub
Skip to content
This repository was archived by the owner on Apr 7, 2026. It is now read-only.

fix: fix unclosed literal error for consecutive backslashes#4387

Merged
rahul2393 merged 1 commit into
googleapis:mainfrom
rayudu3745:main
Mar 17, 2026
Merged

fix: fix unclosed literal error for consecutive backslashes#4387
rahul2393 merged 1 commit into
googleapis:mainfrom
rayudu3745:main

Conversation

@rayudu3745

Copy link
Copy Markdown
Contributor

Issue: SpannerStatementParser
failed to correctly parse SQL string literals containing consecutive backslashes (e.g., SELECT '\'). When two backslashes were placed together, the parser would incorrectly assume the character immediately following them (like a closing quote) was being escaped. This caused the parser to skip the closing quote and eventually throw an INVALID_ARGUMENT: SQL statement contains an unclosed literal exception on valid SQL.

Fix: Updated SpannerStatementParser.java
to toggle the boolean escape state (lastCharWasEscapeChar = !lastCharWasEscapeChar;) when encountering a backslash. This ensures consecutive backslashes correctly cancel each other out in pairs, perfectly preserving the string literal boundaries.

@rayudu3745 rayudu3745 requested review from a team as code owners March 17, 2026 11:51
@product-auto-label product-auto-label Bot added size: s Pull request size is small. api: spanner Issues related to the googleapis/java-spanner API. labels Mar 17, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request correctly fixes a parsing issue with consecutive backslashes in SQL string literals by toggling the escape state. The changes in SpannerStatementParser.java are logical and the new tests in SpannerStatementParserTest.java effectively validate the fix for removeCommentsAndTrim. I've added a couple of suggestions for further improvement.

@product-auto-label product-auto-label Bot added size: m Pull request size is medium. and removed size: s Pull request size is small. labels Mar 17, 2026
@rahul2393 rahul2393 merged commit f4884a8 into googleapis:main Mar 17, 2026
30 checks passed
gcf-merge-on-green Bot pushed a commit that referenced this pull request Mar 17, 2026
🤖 I have created a release *beep* *boop*
---


## [6.112.0](https://togithub.com/googleapis/java-spanner/compare/v6.111.1...v6.112.0) (2026-03-17)


### Features

* Ability to update credentials on long running client ([#4371](https://togithub.com/googleapis/java-spanner/issues/4371)) ([e238990](https://togithub.com/googleapis/java-spanner/commit/e238990077badb063b1b05b0d71f58859434f7ee))
* Add SI, adapt, split point related proto ([7aa4d90](https://togithub.com/googleapis/java-spanner/commit/7aa4d90cd4f001713ee2b0b5113303a748b237e0))
* **spanner:** Include cache updates and routing hint into BeginTransaction and Commit request/response respectively ([7aa4d90](https://togithub.com/googleapis/java-spanner/commit/7aa4d90cd4f001713ee2b0b5113303a748b237e0))


### Bug Fixes

* **deps:** Update the Java code generator (gapic-generator-java) to 2.67.0 ([7aa4d90](https://togithub.com/googleapis/java-spanner/commit/7aa4d90cd4f001713ee2b0b5113303a748b237e0))
* Fix unclosed literal error for consecutive backslashes ([#4387](https://togithub.com/googleapis/java-spanner/issues/4387)) ([f4884a8](https://togithub.com/googleapis/java-spanner/commit/f4884a83d15dcff6e246c7db47c8bafc3369a0a3))

---
This PR was generated with [Release Please](https://togithub.com/googleapis/release-please). See [documentation](https://togithub.com/googleapis/release-please#release-please).
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api: spanner Issues related to the googleapis/java-spanner API. size: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants