Repository navigation
fix(condition): return an empty string for a missing query parameter - #8792
Sean-Walker0 wants to merge 2 commits into
Conversation
QueryParameterData.builder returned getFirst(paramName) verbatim, so a missing query parameter produced null — unlike its siblings HeaderParameterData and CookieParameterData, which return an empty string when the requested entry is absent. The null flowed into the string predicate judges, whose startsWith/contains/regex calls throw NullPointerException, failing the whole request with a 500 instead of simply not matching. The builder now maps a missing parameter to an empty string, matching the header and cookie siblings. The regression tests cover the missing parameter directly and the four downstream string judges; the judge test previously failed with NullPointerException and passes after the fix. Verification: ./mvnw -pl shenyu-plugin/shenyu-plugin-base -am test green (447 tests) with checkstyle clean.
|
/retest All 10 workflow runs created on 2026-11-30T14:43Z have been stuck in |
Aias00
left a comment
There was a problem hiding this comment.
Comment. No blocking findings; one non-blocking suggestion.
- [suggestion][Q9] verified:
QueryParameterDataTest.java:75-82calls the judges directly and bypassesPredicateJudgeFactory.judge, which returns false for blankrealDatabefore invoking those judges;AndMatchStrategy/OrMatchStrategyuse that factory. The reported request-level NPE/500 is therefore not reachable through the production matcher. Please correct the PR description's claim and, if request-level coverage is intended, assert throughPredicateJudgeFactory.judgeorAndMatchStrategy.
Verification
- Reviewed base
ea93a352d29fd217618ec431455c513c1b7ea515against head60ba23927c1a322b734aef17d3a2d123f2e82899(two files).build,pr_build,new-code-quality(added-lines) andcheck-license-headerreport success;issue-spec-policyis NEUTRAL (advisory observe mode) because the PR omits the template's IssueSpec fields.
konlue
left a comment
There was a problem hiding this comment.
Scope
This aligns QueryParameterData.builder with its siblings: a query parameter absent from the request now yields an empty string instead of null, matching HeaderParameterData (line 35) and CookieParameterData (line 37). The production change is one statement plus an import, and the PR adds a builder assertion and a judge-level test. The motivation is consistency, and the behaviour analysis below explains why this is a safe consistency fix rather than the crash fix the description claims.
Verification at 60ba239 (PR +38 −1, 2 files)
In a detached worktree at the PR head, shenyu-plugin-base is 458/0/0 and QueryParameterDataTest is 3/0/0, with checkstyle reporting 0 violations; the 11-module reactor totals 1396 tests with 4 skipped. Reverting only the builder body to getFirst(paramName) turns both new tests red: the builder test with expected: <> but was: <null>, and the judge test with NullPointerException: Cannot invoke "String.startsWith(String)" because "realData" is null inside StartsWithPredicateJudge. A temporary probe, deleted afterwards, routed the missing-parameter data through PredicateJudgeFactory.judge for startsWith, contains, endsWith, regex, = and isBlank, and through AndMatchStrategy and OrMatchStrategy. It passes on both the old and the new implementation, and the per-operator results are identical: false for the five string operators and true for isBlank. The probe also confirms that ?key= and a truly absent parameter evaluate the same, and that a repeated parameter still returns the first value through getFirst.
Behaviour analysis
The description says a missing query parameter crashes the string judges and fails the request with a 500. That path is not reachable in production: every production caller goes through PredicateJudgeFactory.judge, and line 57 returns false for a blank realData before invoking any non-blank judge. StringUtils.isBlank(null) and isBlank("") are both true, so pre-fix and post-fix results are identical. The only other consumer of the built query string is the divide canary sticky key, which starts with isBlank and returns STABLE either way. A repository-wide grep finds PredicateJudgeFactory.judge only at AndMatchStrategy:37 and OrMatchStrategy:37, so custom SPI judges inherit the same guard.
The related claim that this closes the null realData family is not accurate: PostParameterData still returns null in three branches, and DomainParameterData can return a null host. They are equally protected by the factory guard, so that is a wording issue rather than a defect, but the description would read correctly if it said the change makes the query builder consistent with its siblings.
Test coverage
The builder test is load-bearing: it fails on the old code with the exact <null> output, and it is the one assertion that distinguishes the two implementations. The judge test is not load-bearing for the reported bug because it calls the judges directly, bypassing the factory. It proves the new builder contract feeds the judges safely, but it cannot reproduce a request-level failure, and the inline note suggests routing it through PredicateJudgeFactory.judge or AndMatchStrategy, plus covering endsWith and regex, both of which the description names.
Verdict
APPROVE. The mapping is consistent with header and cookie semantics, the builder test pins it, and the change is behaviour-preserving on every production path. The suggestions are about the description and the test's path, not the production change.
| conditionData.setParamValue("value"); | ||
|
|
||
| // before the fix the null realData threw NullPointerException inside the judges | ||
| assertFalse(new StartsWithPredicateJudge().judge(conditionData, |
There was a problem hiding this comment.
These assertions call the judges directly, and that is the only path where a null realData throws. In production every call goes through PredicateJudgeFactory.judge, which returns false for a blank realData before reaching a non-blank judge (isBlank(null) == isBlank("") == true), so the claimed request-level NPE/500 is not reproducible. Please route this case through PredicateJudgeFactory.judge or AndMatchStrategy, and cover endsWith and regex, which the description names but the test omits. A probe through the factory is green on both the old and the new implementation, which is the correct signal for a consistency change.
| // a missing parameter behaves like a missing header or cookie: empty string, | ||
| // so the string predicate judges never receive null | ||
| String value = exchange.getRequest().getQueryParams().getFirst(paramName); | ||
| return Objects.nonNull(value) ? value : ""; |
There was a problem hiding this comment.
The mapping itself is right and matches HeaderParameterData and CookieParameterData. Please adjust the description's claim that this fixes a request-level 500: PredicateJudgeFactory line 57 already returns false for a blank realData, and the only other consumer, the divide canary sticky key, checks isBlank too, so pre-fix and post-fix behaviour is identical on every production path. Also, PostParameterData still returns null in three branches, so this does not close the null realData family; it aligns the query builder with its siblings.
|
|
||
| import org.apache.shenyu.spi.Join; | ||
|
|
||
| import java.util.Objects; |
There was a problem hiding this comment.
Sibling classes keep java.util.* after the Spring imports (HeaderParameterData does), so this import reads better at the end of the block. Checkstyle does not enforce import order here (CustomImportOrder is commented out), so this is purely cosmetic.
…actory Addresses the review on apache#8792: PredicateJudgeFactory.judge short-circuits a blank realData to false before any non-blank judge runs, so the production path never threw — the direct judge calls in the test were the only reachable NPE. The test now drives startsWith, endsWith, regex, contains, equals and isBlank through the factory, matching the production route and covering the operators the description named but the test omitted. Also moves the java.util import after the Spring imports to match the sibling builders, and the PR description is corrected separately.
|
All three points addressed:
|
Problem
QueryParameterData.builderreturnedgetFirst(paramName)verbatim, so a rule condition on a query parameter that is absent from the request produced null — unlike its siblingsHeaderParameterDataandCookieParameterData, which return an empty string for a missing entry.Correction over the original description (per review): the production matching path routes through
PredicateJudgeFactory.judge, which already short-circuits a blankrealDatato false before any non-blank judge runs, so the pre-fix behaviour was not a request-level 500. What this change actually is: a consistency alignment of the query builder with its header and cookie siblings, so the value shape a condition evaluates (and any current or future direct judge consumer, such as the divide canary sticky-key path's own blank guard) is""instead of null. It also does not close the nullrealDatafamily —PostParameterDatastill returns null in three branches.Modifications
QueryParameterData.buildermaps a missing parameter to an empty string, matching the header and cookie siblings.PredicateJudgeFactory.judge— the production route — coveringstartsWith,endsWith,regex,contains,equalsandisBlank, and asserts the builder returns""directly.java.utilimport ordering now matches the sibling builders.Verifying this change
./mvnw -pl shenyu-plugin/shenyu-plugin-base -am test -Bgreen (447 tests), checkstyle cleanNotes
QueryParameterData.javais not touched by any of them.For all changes: