{"record":{"id":"fd3b6613a288e4ba","repo":"alibaba/COLA","slug":"errorcode","errorCode":"${errorCode}","errorMessage":"${errMessage}","messagePattern":"\\$\\{errMessage\\}","errorType":"error_code","errorClass":"BizException","httpStatus":null,"severity":"error","filePath":"cola-components/cola-component-exception/src/main/java/com/alibaba/cola/exception/Assert.java","lineNumber":42,"sourceCode":" * @date 2019-01-13 11:49 AM\n */\npublic abstract class Assert {\n\n    /**\n     * Assert a boolean expression, throwing {@code BizException}\n     *\n     * for example\n     *\n     * <pre class=\"code\">Assert.isTrue(i != 0, errorCode.B_ORDER_illegalNumber, \"The order number can not be zero\");</pre>\n     *\n     * @param expression a boolean expression\n     * @param errorCode\n     * @param errMessage the exception message to use if the assertion fails\n     * @throws BizException if expression is {@code false}\n     */\n    public static void isTrue(boolean expression, String errorCode, String errMessage) {\n        if (!expression) {\n            throw new BizException(errorCode, errMessage);\n        }\n    }\n\n    /**\n     * Assert a boolean expression, if expression is true, throwing {@code BizException}\n     *\n     * for example\n     *\n     * <pre class=\"code\">Assert.isFalse(i == 0, errorCode.B_ORDER_illegalNumber, \"The order number can not be zero\");</pre>\n     *\n     * This is more intuitive than isTure.\n     */\n    public static void isFalse(boolean expression, String errorCode, String errMessage) {\n        if (expression) {\n            throw new BizException(errorCode, errMessage);\n        }\n    }\n","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/alibaba/COLA/blob/352e1a867538d9cd40e1b11e4028fa652fc97557/cola-components/cola-component-exception/src/main/java/com/alibaba/cola/exception/Assert.java#L24-L60","documentation":"Assert.isTrue(boolean, String errorCode, String errMessage) is a convenience assertion that throws BizException(errorCode, errMessage) when the given expression is false. The message and error code are caller-supplied, so they appear as ${errMessage}/${errorCode} in the template.","triggerScenarios":"Calling Assert.isTrue(expression, errorCode, msg) where expression evaluates to false at runtime — e.g. Assert.isTrue(order != null, ErrorCode.B_ORDER_notFound, \"Order not found\").","commonSituations":"Precondition checks on request parameters or loaded entities failing; null/invalid inputs reaching service code that uses COLA's Assert utility for validation.","solutions":["Inspect the thrown errMessage/errCode to identify which assertion failed and why the expression was false.","Validate the input/state before the call, or fix the upstream logic that produced the unexpected value.","If the assertion is wrong, correct the condition; if it is a legitimate business rule failure, handle BizException at the API boundary."],"exampleFix":"// before\nAssert.isTrue(order.getCount() > 0, ErrorCode.B_ORDER_illegalNumber, \"count must be positive\"); // throws when count<=0\n// after\nif (order.getCount() <= 0) {\n    return Response.buildFailure(ErrorCode.B_ORDER_illegalNumber.getErrCode(), \"count must be positive\");\n}\nAssert.isTrue(order.getCount() > 0, ErrorCode.B_ORDER_illegalNumber, \"count must be positive\");","handlingStrategy":"validation","validationCode":"if (order == null || order.getCount() <= 0) {\n    return Response.buildFailure(ErrorCode.B_ORDER_illegalNumber.getErrCode(), \"count must be positive\");\n}\nAssert.isTrue(order.getCount() > 0, ErrorCode.B_ORDER_illegalNumber, \"count must be positive\");","typeGuard":null,"tryCatchPattern":"try {\n    Assert.isTrue(expr, errorCode, errMessage);\n} catch (BizException e) {\n    return Response.buildFailure(e.getErrCode(), e.getErrMessage());\n}","preventionTips":["Check the asserted condition explicitly and return a business failure before reaching the assert.","Use meaningful, unique ErrorCodes so the thrown BizException is diagnosable from logs.","Keep assertion messages actionable (state what was expected vs actual)."],"tags":["assertion","validation","cola"],"backgroundTag":"invalid-argument-value","analyzedSha":"352e1a867538d9cd40e1b11e4028fa652fc97557","analyzedAt":"2026-09-08T00:46:23.972Z","contentChangedAt":"2026-09-08T00:46:23.972Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}