Skip to content

fix(condition): treat a missing request value as no-match in time predicates - #8635

Open
Sean-Walker0 wants to merge 1 commit into
apache:masterfrom
Sean-Walker0:fix/time-predicate-missing-value
Open

Sean-Walker0 wants to merge 1 commit into
apache:masterfrom
Sean-Walker0:fix/time-predicate-missing-value

Conversation

@Sean-Walker0

Copy link
Copy Markdown
Contributor

Problem

The TimeBefore/TimeAfter judges pass realData — the request-side value built from the exchange — straight into DateUtils.parseLocalDateTime inside judge. When the configured header or query parameter is absent from the request, buildRealData returns null and LocalDateTime.parse(null, formatter) throws NullPointerException, 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

  • Both judges return false when realData is 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.
  • The configured-time parsing stays exactly where it is (outside the catch), preserving the [ISSUE #8357] Keep malformed request dates from aborting condition matching #8358 fail-fast behaviour for admin-side mistakes: testInvalidConfiguredTimeStillFails passes unchanged.
  • Regression test asserts: null request value → false without an exception (red-light verified: NullPointerException: text before the fix), and the normal before/after comparisons still work for present values.

Verifying this change

Notes

  • Orthogonal to all open PRs: TimerBeforePredicateJudge/TimerAfterPredicateJudge are not touched by any of them.
  • Behavior change is confined to the missing-request-value path (crash → no-match); malformed-configured-time and malformed-request-value semantics are byte-for-byte unchanged.

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

…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 wy471x 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.

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)

  1. Drop the change — there is no missing-value bug; the malformed-value contract from #8358 is already the whole story (PredicateJudgeFactory covers "missing", the try/catch in the judges covers "present but unparseable").
  2. 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.

@Sean-Walker0

Copy link
Copy Markdown
Contributor Author

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 — PredicateJudgeFactory.judge short-circuits a blank realData to false before any non-blank judge runs, and my regression test reached the judge directly, bypassing that guard. The null guard in the two time judges is therefore a defensive alignment with the factory contract rather than a production fix; behaviour on every production path is identical before and after. The code change itself remains sound and the tests valid as judge-level contracts, but the impact statement in the description (and any earlier report of mine implying a 500) should be read with this correction. Apologies for the overstated claim.

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.

2 participants