{"record":{"id":"785db6e93d478c97","repo":"prestodb/presto","slug":"unsupported-flip-non-comparison-operator","errorCode":null,"errorMessage":"Unsupported flip non-comparison operator: ","messagePattern":"Unsupported flip non-comparison operator: ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/function/OperatorType.java","lineNumber":117,"sourceCode":"    public static OperatorType flip(OperatorType operator)\n    {\n        switch (operator) {\n            case EQUAL:\n                return EQUAL;\n            case NOT_EQUAL:\n                return NOT_EQUAL;\n            case LESS_THAN:\n                return GREATER_THAN;\n            case LESS_THAN_OR_EQUAL:\n                return GREATER_THAN_OR_EQUAL;\n            case GREATER_THAN:\n                return LESS_THAN;\n            case GREATER_THAN_OR_EQUAL:\n                return LESS_THAN_OR_EQUAL;\n            case IS_DISTINCT_FROM:\n                return IS_DISTINCT_FROM;\n            default:\n                throw new IllegalArgumentException(\"Unsupported flip non-comparison operator: \" + operator);\n        }\n    }\n\n    public static OperatorType negate(OperatorType operator)\n    {\n        switch (operator) {\n            case EQUAL:\n                return NOT_EQUAL;\n            case NOT_EQUAL:\n                return EQUAL;\n            case LESS_THAN:\n                return GREATER_THAN_OR_EQUAL;\n            case LESS_THAN_OR_EQUAL:\n                return GREATER_THAN;\n            case GREATER_THAN:\n                return LESS_THAN_OR_EQUAL;\n            case GREATER_THAN_OR_EQUAL:\n                return LESS_THAN;","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/function/OperatorType.java#L99-L135","documentation":"OperatorType.flip() only maps comparison operators (equality, ordering, IS_DISTINCT_FROM) to their flipped counterparts. Passing any non-comparison operator (arithmetic, logical, etc.) hits the default branch and throws IllegalArgumentException.","triggerScenarios":"Calling OperatorType.flip(operator) with a non-comparison OperatorType such as ADD, SUBTRACT, AND, OR, HASH_CODE, etc.","commonSituations":"Rewriting commuted predicates in optimizer rules where the operator came from arbitrary function resolution; version drift where a new OperatorType enum constant was added but flip() was not updated; applying flip to an operator obtained from a generic expression tree.","solutions":["Only call flip() on comparison-family operators; guard with an EnumSet of comparable operators first","Add a case for any newly added operator to flip()'s switch","Use negate() or explicit mapping for non-comparison operators as appropriate","Check the operator kind (e.g. isComparisonOperator) before flipping"],"exampleFix":"// before\nOperatorType flipped = OperatorType.flip(operator); // operator may be ADD\n// after\nif (COMPARISON_OPERATORS.contains(operator)) {\n    OperatorType flipped = OperatorType.flip(operator);\n}","handlingStrategy":"validation","validationCode":"private static final Set<OperatorType> COMPARISONS = EnumSet.of(\n    OperatorType.EQUAL, OperatorType.NOT_EQUAL, OperatorType.LESS_THAN,\n    OperatorType.LESS_THAN_OR_EQUAL, OperatorType.GREATER_THAN,\n    OperatorType.GREATER_THAN_OR_EQUAL, OperatorType.IS_DISTINCT_FROM);\nif (!COMPARISONS.contains(op)) throw new IllegalArgumentException(\"not flippable: \" + op);","typeGuard":"boolean isComparison(OperatorType op) { return COMPARISONS.contains(op); }","tryCatchPattern":"try { flipped = OperatorType.flip(op); } catch (IllegalArgumentException e) { /* fall back: keep original operator or handle non-comparison case */ }","preventionTips":["Maintain an EnumSet whitelist of comparison operators","Update flip/negate switches whenever OperatorType gains constants","Never apply flip to operators sourced from unvalidated expression trees"],"tags":["operator","illegal-argument","enum-switch"],"backgroundTag":"unsupported-operation","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}