Skip to content

Rust resolver treats empty range rule as always matching #296

@nicklasl

Description

@nicklasl

Problem

An empty range rule (rangeRule {} with no start or end bounds) matches any value in the Rust resolver. Java treats it as non-matching.

Rust behavior

confidence-resolver/src/value.rs ~L162-187:

fn evaluate_range_rule(
    range_rule: &targeting::RangeRule,
    context_value: &targeting::Value,
) -> bool {
    let after_start = match &range_rule.start {
        Some(...) => ...,
        _ => false,
    };
    let before_end = match &range_rule.end {
        Some(...) => ...,
        _ => false,
    };
    (range_rule.start.is_none() || after_start) && (range_rule.end.is_none() || before_end)
}

When both start and end are None:

  • range_rule.start.is_none()true
  • range_rule.end.is_none()true
  • Result: true && true = true (matches)

Java behavior

EvalUtil.java ~L167-178:

public static boolean isInRange(Targeting.RangeRule rangeRule, Targeting.Value value) {
    if (value == null) {
        return false;
    }
    try {
        return Util.hasOverlap(value, rangeRule);
    } catch (IllegalArgumentException e) {
        return false;
    }
}

Java delegates to Util.hasOverlap() which requires at least one bound to be set. An empty range has VALUE_NOT_SET for its expected type:

private static ValueCase getExpectedPrimitiveType(Targeting.RangeRule rangeRule) {
    if (rangeRule.hasStartInclusive()) return rangeRule.getStartInclusive().getValueCase();
    else if (rangeRule.hasStartExclusive()) return rangeRule.getStartExclusive().getValueCase();
    else if (rangeRule.hasEndInclusive()) return rangeRule.getEndInclusive().getValueCase();
    else if (rangeRule.hasEndExclusive()) return rangeRule.getEndExclusive().getValueCase();
    else return ValueCase.VALUE_NOT_SET;
}

With no bounds, the type check fails and the range does not match → NO_SEGMENT_MATCH.

Affected spec tests

  • empty_range_rule

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions