Repository navigation
#4210 fix: [cypher] MERGE+UNWIND crash on single-quote property value - #4237
Conversation
MergeStep.matchesProperties() and setProperties() stripped surrounding
quotes from string property values via substring(1, len-1), with no
length guard. A property value equal to the single character ' (or ")
satisfied both startsWith and endsWith and triggered substring(1, 0),
throwing StringIndexOutOfBoundsException ("Range [1, 0) out of bounds
for length 1").
The stripping was also dead: by the time these methods run,
evaluateProperties has already resolved literals (LiteralExpression
returns unquoted values, CypherExpressionBuilder.tryParseLiteral has a
length >= 2 guard) and expressions/parameters to plain Java objects.
Beyond the crash, the code would silently corrupt any genuine value
that happened to start and end with a quote (e.g. "'wrapped'" stored
as "wrapped").
Removed the stripping blocks from both methods. Added
Issue4210MergeUnwindSingleQuoteTest covering the crash case, repeated
ON MATCH execution, and value-fidelity for quote-wrapped strings.
Code ReviewOverviewThis PR fixes a Correctness - Looks GoodThe root cause analysis is accurate:
Removing both blocks is the correct fix. Code Quality
Test CoverageThe regression test covers the important cases:
Two minor issues in the test file: 1. Unclosed final ResultSet rs = database.query("opencypher", "MATCH (n:Token) RETURN n.value AS val");
assertThat(rs.hasNext()).isTrue();
assertThat(rs.next().<String>getProperty("val")).isEqualTo("'");
// rs is never closed - resource leak
2. Multi-line class Javadoc The class-level Summary
The core fix is solid. The two test-file issues above are minor but worth addressing before merge. |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
🟢 Coverage 100.00% diff coverage · -7.48% coverage variation
Metric Results Coverage variation ✅ -7.48% coverage variation Diff coverage ✅ 100.00% diff coverage Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (8bacfb9) 127073 93641 73.69% Head commit (a46ec56) 158736 (+31663) 105101 (+11460) 66.21% (-7.48%) Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#4237) 3 3 100.00% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
There was a problem hiding this comment.
Code Review
This pull request resolves GitHub issue #4210 by removing logic in MergeStep.java that incorrectly stripped quotes from string property values, which could lead to StringIndexOutOfBoundsException. A new regression test suite, Issue4210MergeUnwindSingleQuoteTest, was added to verify the fix. Review feedback suggests further improving Cypher compliance by allowing null property matches in matchesProperties and recommends using try-with-resources in the test code to ensure ResultSet resources are properly managed.
| else if (strValue.startsWith("\"") && strValue.endsWith("\"")) | ||
| expectedValue = strValue.substring(1, strValue.length() - 1); | ||
| } | ||
| final Object expectedValue = entry.getValue(); |
There was a problem hiding this comment.
While cleaning up this method, it's worth noting that the actualValue == null check (on line 912 in the context) prevents MERGE from matching properties that are explicitly null or missing. In Cypher, MERGE should match when both the pattern and the document have a null value for a property. Since valuesEqual already handles null comparisons correctly, this check is likely incorrect and could be removed to improve Cypher compliance.
There was a problem hiding this comment.
Out of scope for this PR. The reported issue is the substring crash; removing the early actualValue == null check changes MERGE's null-matching semantics (whether a missing/null property in the document satisfies a pattern that supplies a null/missing key), which is a separate behavioural concern and would need its own TCK-coverage analysis and tests. Leaving as-is for this fix.
| final ResultSet rs = database.command("opencypher", query, params); | ||
| int count = 0; | ||
| while (rs.hasNext()) { | ||
| rs.next(); | ||
| count++; | ||
| } | ||
| assertThat(count).isEqualTo(4); |
There was a problem hiding this comment.
There was a problem hiding this comment.
Fixed in a46ec56 - all three ResultSet sites wrapped in try-with-resources.
| final ResultSet rs = database.command("opencypher", query, params); | ||
| int count = 0; | ||
| while (rs.hasNext()) { | ||
| final var row = rs.next(); | ||
| assertThat(row.<Boolean>getProperty("created")).isFalse(); | ||
| count++; | ||
| } | ||
| assertThat(count).isEqualTo(4); |
There was a problem hiding this comment.
The ResultSet should be closed to ensure that database resources are released. Using try-with-resources is the recommended approach.
try (ResultSet rs = database.command("opencypher", query, params)) {
int count = 0;
while (rs.hasNext()) {
final var row = rs.next();
assertThat(row.<Boolean>getProperty("created")).isFalse();
count++;
}
assertThat(count).isEqualTo(4);
}| final ResultSet rs = database.query("opencypher", "MATCH (n:Token) RETURN n.value AS val"); | ||
| assertThat(rs.hasNext()).isTrue(); | ||
| assertThat(rs.next().<String>getProperty("val")).isEqualTo("'"); |
There was a problem hiding this comment.
The ResultSet should be closed to ensure that database resources are released. Using try-with-resources is the recommended approach.
try (ResultSet rs = database.query("opencypher", "MATCH (n:Token) RETURN n.value AS val")) {
assertThat(rs.hasNext()).isTrue();
assertThat(rs.next().<String>getProperty("val")).isEqualTo("'");
}
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4237 +/- ##
=======================================
Coverage 64.63% 64.64%
=======================================
Files 1644 1644
Lines 127073 127058 -15
Branches 27217 27211 -6
=======================================
+ Hits 82136 82139 +3
+ Misses 33460 33448 -12
+ Partials 11477 11471 -6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ResultSet is AutoCloseable; wrap the three open() sites in try-with-resources to release database resources deterministically.
|
Addressing the two test-file points from the review:
|
Code ReviewOverviewThis PR removes genuinely dead and crash-prone stripping code from Correctness - ConfirmedThe root cause analysis in the PR description is accurate:
Removing both blocks is the correct fix. Code Style - Consistent
Test CoverageCorrection to prior review: Both test methods correctly use try-with-resources for The test scenarios are well-chosen:
One gap worth addressing: The removed code handled both single-quote and double-quote stripping symmetrically. A Minor Style IssueThe class-level Summary
The core fix is solid. The double-quote test gap and style nit are minor but worth addressing before merge. |
Summary
-> Range [1, 0) out of bounds for length 1error #4210.MergeStep.matchesPropertiesandsetPropertiesstripped surrounding quotes from string property values withsubstring(1, len-1)and no length guard, so a value equal to a single'(or") crashed withStringIndexOutOfBoundsException: Range [1, 0) out of bounds for length 1.LiteralExpression.getValue()(parsed viaCypherExpressionBuilder.tryParseLiteral, which has its ownlength >= 2guard), andevaluatePropertiesresolves expressions/parameters to plain Java values before either method runs. The block additionally would silently corrupt genuine values that happen to start and end with a quote (e.g.'wrapped'stored aswrapped).Test plan
Issue4210MergeUnwindSingleQuoteTestreproduces the originalUNWIND $batch ... MERGE (n:NER {...})crash with a single-quote property value, plus value-fidelity for quote-wrapped strings; both pass.