{"record":{"id":"2e52c08100aaec9d","repo":"prestodb/presto","slug":"unsupported-negate-non-comparison-operator","errorCode":null,"errorMessage":"Unsupported negate non-comparison operator: ","messagePattern":"Unsupported negate 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":137,"sourceCode":"    }\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;\n            default:\n                throw new IllegalArgumentException(\"Unsupported negate non-comparison operator: \" + operator);\n        }\n    }\n}\n","sourceCodeStart":119,"sourceCodeEnd":141,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/function/OperatorType.java#L119-L141","documentation":"Sentinel in the operator negation switch: negate() only maps comparison operators (EQUAL, LESS_THAN, etc.); any other OperatorType reaches the default branch and is rejected because negation is undefined for it.","triggerScenarios":"Calling OperatorType.negate(operator) with a non-comparison operator such as ADD, MULTIPLY, IS_NULL, LIKE, etc.","commonSituations":"NOT-elimination or predicate pushdown rules negating operators sourced from generic expressions; a newly added OperatorType constant missing from the negate switch; misusing negate where flip or logical NOT was intended.","solutions":["Only call negate on comparison operators","Add an explicit case if a new comparison operator is introduced"],"exampleFix":"// before\nOperatorType negated = OperatorType.negate(operator); // throws for ADD\n// after\nif (COMPARISON_OPERATORS.contains(operator)) {\n    OperatorType negated = OperatorType.negate(operator);\n} else {\n    expression = not(expression); // logical negation\n}","handlingStrategy":"type-guard","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);\nif (!COMPARISONS.contains(op)) throw new IllegalArgumentException(\"not negatable: \" + op);","typeGuard":"boolean isComparison(OperatorType op) { return COMPARISONS.contains(op); }","tryCatchPattern":"try { negated = OperatorType.negate(op); } catch (IllegalArgumentException e) { expression = NotExpression of original; }","preventionTips":["Use logical NOT wrapping for non-comparison operators","Keep comparison-operator whitelist next to flip/negate call sites","Audit switch coverage when adding OperatorType constants"],"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"}