Skip to content

fix: handle null operands in LogicOrOperator for consistency with && and ! - #460

Open
chenjunwenhao wants to merge 1 commit into
alibaba:mainfrom
chenjunwenhao:fix/logic-or-operator-null-handling
Open

fix: handle null operands in LogicOrOperator for consistency with && and !#460
chenjunwenhao wants to merge 1 commit into
alibaba:mainfrom
chenjunwenhao:fix/logic-or-operator-null-handling

Conversation

@chenjunwenhao

Copy link
Copy Markdown
Contributor

Summary

LogicAndOperator and LogicNotOperator both treat null as false, but LogicOrOperator throws INVALID_BINARY_OPERAND when either operand is null. This inconsistency causes null || true to fail at runtime while null && true correctly returns false and !null correctly returns true.

Problem

// These all work:
null && true   // → false
null && null   // → false
!null          // → true

// This throws INVALID_BINARY_OPERAND:
null || true   // Expected: true, Actual: error
null || null   // Expected: false, Actual: error

Fix

Add null-to-false conversion in LogicOrOperator.execute(), matching the pattern already used in LogicAndOperator and LogicNotOperator:

if (leftValue == null) {
    leftValue = false;
}
if (rightValue == null) {
    rightValue = false;
}

Tests

Added logic_or_null.ql test suite covering:

  • || operator with null operands (left, right, both)
  • or keyword with null operands
  • Consistency with !null behavior

Changed Files

  • src/main/java/.../runtime/operator/logic/LogicOrOperator.java — added null handling
  • src/test/resources/testsuite/independent/operator/logic_or_null.ql — new test suite

…and !

LogicAndOperator and LogicNotOperator both treat null as false, but
LogicOrOperator throws INVALID_BINARY_OPERAND when either operand is
null. This makes `null || true` fail at runtime while `null && true`
correctly returns false. Add null-to-false conversion to align the
behavior across all three logical operators.
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.

1 participant