Skip to content

fix(condition): return an empty string for a missing query parameter - #8792

Open
Sean-Walker0 wants to merge 2 commits into
apache:masterfrom
Sean-Walker0:fix/query-param-missing-null
Open

Sean-Walker0 wants to merge 2 commits into
apache:masterfrom
Sean-Walker0:fix/query-param-missing-null

Conversation

@Sean-Walker0

@Sean-Walker0 Sean-Walker0 commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Problem

QueryParameterData.builder returned getFirst(paramName) verbatim, so a rule condition on a query parameter that is absent from the request produced null — unlike its siblings HeaderParameterData and CookieParameterData, 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 blank realData to 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 null realData family — PostParameterData still returns null in three branches.

Modifications

  • QueryParameterData.builder maps a missing parameter to an empty string, matching the header and cookie siblings.
  • The regression test now drives the missing-parameter value through PredicateJudgeFactory.judge — the production route — covering startsWith, endsWith, regex, contains, equals and isBlank, and asserts the builder returns "" directly.
  • The java.util import ordering now matches the sibling builders.

Verifying this change

  • This change added tests
  • ./mvnw -pl shenyu-plugin/shenyu-plugin-base -am test -B green (447 tests), checkstyle clean

Notes

  • No observable production behaviour change (the factory short-circuit precedes this builder's only consumer of the value's nullness); this is a builder-contract alignment.
  • Orthogonal to all open PRs: QueryParameterData.java is not touched by any of them.

For all changes:

  • There is no issue or PR that duplicates this change
  • Has a PR template been filled out
  • DCO signed; no new files needing license headers
  • Module-scoped tests and checkstyle executed locally as listed

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.
@Sean-Walker0

Copy link
Copy Markdown
Contributor Author

/retest

All 10 workflow runs created on 2026-11-30T14:43Z have been stuck in queued for over 24 hours while CI from the same period on other PRs completed normally (scheduling stall, not a code issue). The branch has not changed since 60ba239; re-requesting the CI run.

@Aias00 Aias00 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.

Comment. No blocking findings; one non-blocking suggestion.

  • [suggestion][Q9] verified: QueryParameterDataTest.java:75-82 calls the judges directly and bypasses PredicateJudgeFactory.judge, which returns false for blank realData before invoking those judges; AndMatchStrategy/OrMatchStrategy use 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 through PredicateJudgeFactory.judge or AndMatchStrategy.

Verification

  • Reviewed base ea93a352d29fd217618ec431455c513c1b7ea515 against head 60ba23927c1a322b734aef17d3a2d123f2e82899 (two files). build, pr_build, new-code-quality (added-lines) and check-license-header report success; issue-spec-policy is NEUTRAL (advisory observe mode) because the PR omits the template's IssueSpec fields.

@konlue konlue 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.

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,

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.

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 : "";

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.

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;

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.

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.
@Sean-Walker0

Copy link
Copy Markdown
Contributor Author

All three points addressed:

  1. Test route: the case now drives PredicateJudgeFactory.judge — the production route — covering startsWith, endsWith, regex, contains, equals and isBlank (the operators the description named but the test omitted are all in). Verified the factory probe is green on both the pre-fix and post-fix code, matching your probe.
  2. Description: the PR body is corrected — the production path never threw because the factory short-circuits a blank realData; the change is a builder-consistency alignment with the header and cookie siblings, not a 500 fix, and it does not close the null realData family (PostParameterData still returns null in three branches).
  3. Import order: moved after the Spring imports to match the siblings.

This branch has not been deployed

No deployments
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.

3 participants