Repository navigation
fix(condition): treat a missing request value as no-match in time predicates - #8635
Sean-Walker0 wants to merge 1 commit into
Conversation
…dicates The TimeBefore/TimeAfter judges parse the request-side value inside the try block but pass realData straight into DateUtils.parseLocalDateTime: when the configured header or query parameter is absent from the request, realData is null and LocalDateTime.parse throws NullPointerException, which escapes the judge and fails the whole request with a 500. apache#8358 established the request-side contract — a malformed request date never aborts matching (testInvalidRequestTimeDoesNotPreventOtherConditions) — but only covered values that are present yet unparseable. The judges now return false when realData is missing, keeping the configured-time fail-fast behaviour of apache#8358 untouched (testInvalidConfiguredTimeStillFails passes unchanged). The regression test previously failed with NullPointerException: text and passes after the fix; the positive comparison cases are asserted alongside. Verification: ./mvnw -pl shenyu-plugin/shenyu-plugin-base -am test green (447 tests) with checkstyle clean.
wy471x
left a comment
There was a problem hiding this comment.
Review — treat a missing request value as no-match in time predicates
Thanks for the detailed write-up. Verified locally: ./mvnw -pl shenyu-plugin/shenyu-plugin-base -am test -Dtest=PredicateJudgeTest -Dsurefire.failIfNoSpecifiedTests=false -Djacoco.skip=true -Drat.skip=true → BUILD SUCCESS, checkstyle clean, RAT clean.
Blocking — the reported crash cannot happen on the production path
The problem statement says the NPE "escapes the judge" and that "every request that reaches such a rule fails with a 500". That is not reachable today:
PredicateJudgeFactory.judge already short-circuits before any judge runs:
PredicateJudge predicateJudge = newInstance(conditionData.getOperator());
if (!(predicateJudge instanceof BlankPredicateJudge) && StringUtils.isBlank(realData)) {
return false;
}
return predicateJudge.judge(conditionData, realData);StringUtils.isBlank(null) is true, and TimeBefore/TimeAfter are not BlankPredicateJudge, so a missing header/query value has always returned false without parsing. I confirmed it against this branch with a throw-away probe that goes through the factory (OperatorEnum.TIME_BEFORE, realData = null / "" / " "): all three return false, no exception. The only callers of a judge are AndMatchStrategy/OrMatchStrategy, and both go through the factory.
So the new guard is dead code for the gateway, and missingRequestValueDisablesTheTimeCondition exercises a call path (new TimerBeforePredicateJudge().judge(...)) that production never uses. The "red-light" NPE you saw comes from calling the judge directly, not from a request.
Suggested direction (pick one)
- Drop the change — there is no missing-value bug; the malformed-value contract from #8358 is already the whole story (
PredicateJudgeFactorycovers "missing", thetry/catchin the judges covers "present but unparseable"). - If the intent is defence in depth for direct/external callers of the SPI, keep the two guards but say so in the description and assert the behaviour through
PredicateJudgeFactory.judge(conditionData, null)instead of the raw judge, so the test documents a real contract.
Either way the PR description should not claim an existing 500 on missing request values, because the changelog/issue trail would inherit a bug that was never there.
Nits
- The comment "
#8358 keeps malformed values on the same contract" is fine, but the factory already owns the missing-value contract; pointing the comment there avoids the same confusion later.
Verdict: Request changes — the fix is inert on the path it claims to protect; please re-scope or drop it.
|
Correction to this PR's description (surfaced by the review on #8792): the claimed request-level NPE/500 for a missing request value is not reproducible in production — |
Problem
The
TimeBefore/TimeAfterjudges passrealData— the request-side value built from the exchange — straight intoDateUtils.parseLocalDateTimeinsidejudge. When the configured header or query parameter is absent from the request,buildRealDatareturns null andLocalDateTime.parse(null, formatter)throwsNullPointerException, which escapes the judge: nothing in the call chain (MatchStrategyFactory.match→AndMatchStrategy/OrMatchStrategy→AbstractShenyuPlugin.filterRule) catches it, so every request that reaches such a rule fails with a 500.#8358 established the request-side contract — a malformed request date never aborts matching — and locked it in
testInvalidRequestTimeDoesNotPreventOtherConditions, but that test only covers values that are present yet unparseable. A value that is missing (no header / no query parameter) takes a different path and still crashes.Modifications
falsewhenrealDatais blank, before any parsing: a missing request value cannot be evaluated, so the condition simply does not match — the same observable behaviour a malformed value already gets.testInvalidConfiguredTimeStillFailspasses unchanged.falsewithout an exception (red-light verified:NullPointerException: textbefore the fix), and the normal before/after comparisons still work for present values.Verifying this change
./mvnw -pl shenyu-plugin/shenyu-plugin-base -am test -Bgreen (447 tests, including the unchanged [ISSUE #8357] Keep malformed request dates from aborting condition matching #8358 contracts), checkstyle cleanNotes
TimerBeforePredicateJudge/TimerAfterPredicateJudgeare not touched by any of them.For all changes: