{"record":{"id":"b9a62dd7176aba58","repo":"apache/druid","slug":"expected-optimized-path","errorCode":null,"errorMessage":"expected optimized path","messagePattern":"expected optimized path","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions-contrib/compressed-bigdecimal/src/main/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimal.java","lineNumber":386,"sourceCode":"      }\n    }\n  }\n\n  @Override\n  public int compareTo(CompressedBigDecimal o)\n  {\n    return compareTo(o, false);\n  }\n\n  public int compareTo(CompressedBigDecimal o, boolean expectOptimized)\n  {\n    if (super.equals(o)) {\n      return 0;\n    } else if (getScale() == o.getScale()) {\n      return directCompareCompressedBigDecimal(this, o);\n    } else {\n      if (expectOptimized) {\n        throw new IAE(\"expected optimized path\");\n      }\n\n      return this.toBigDecimal().compareTo(o.toBigDecimal());\n    }\n  }\n\n  /**\n   * performs a subtraction of lhs - rhs to compare elements\n   *\n   * @param lhs\n   * @param rhs\n   * @return\n   */\n  private static int directCompareCompressedBigDecimal(CompressedBigDecimal lhs, CompressedBigDecimal rhs)\n  {\n    // this short-circuit serves two functions: 1. it speeds up comparison in +/- cases 2. it avoids the case of\n    // overflow of positive - negative and negative - positive. p - p and n - n both fit in the given allotment of ints\n    if (lhs.isNonNegative() && rhs.isNegative()) {","sourceCodeStart":368,"sourceCodeEnd":404,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-contrib/compressed-bigdecimal/src/main/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimal.java#L368-L404","documentation":"Assertion guard in compareTo(o, expectOptimized): the caller asserted that mixed-scale values never reach the slow BigDecimal-conversion path (e.g. a buffer aggregator guarantees uniform scale); it fired because two values with different scales were compared.","triggerScenarios":"Thrown at extensions-contrib/compressed-bigdecimal/src/main/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimal.java:386 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure all compared values share the same scale (use Utils.objToCompressedBigDecimalWithScale).","If mixed scales are legitimate, call compareTo(o, false) instead of asserting the optimized path."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}