{"record":{"id":"0afe727ac6f2f0d0","repo":"paascloud/paascloud-master","slug":"errorinfo","errorCode":null,"errorMessage":"errorInfo","messagePattern":"errorInfo","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":400,"severity":"warning","filePath":"paascloud-common/paascloud-common-core/src/main/java/com/paascloud/core/aspect/BindingResultAop.java","lineNumber":74,"sourceCode":"\tpublic void doAfter(final JoinPoint joinPoint) {\n\t\tString methodName = joinPoint.getSignature().getName();\n\t\tObject target = joinPoint.getTarget();\n\t\t//得到拦截的方法\n\t\tMethod method = getMethodByClassAndName(target.getClass(), methodName);\n\t\tObject[] objects = joinPoint.getArgs();\n\t\t//方法的参数\n\t\tassert method != null;\n\t\tValidateAnnotation annotation = (ValidateAnnotation) getAnnotationByMethod(method, ValidateAnnotation.class);\n\t\tif (annotation != null) {\n\t\t\tBindingResult bindingResult = null;\n\t\t\tfor (Object arg : objects) {\n\t\t\t\tif (arg instanceof BindingResult) {\n\t\t\t\t\tbindingResult = (BindingResult) arg;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (bindingResult != null && bindingResult.hasErrors()) {\n\t\t\t\tString errorInfo = bindingResult.getFieldError().getDefaultMessage();\n\t\t\t\tthrow new IllegalArgumentException(errorInfo);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * 根据目标方法和注解类型  得到该目标方法的指定注解\n\t */\n\tprivate Annotation getAnnotationByMethod(Method method, Class annoClass) {\n\t\tAnnotation[] all = method.getAnnotations();\n\t\tfor (Annotation annotation : all) {\n\t\t\tif (annotation.annotationType() == annoClass) {\n\t\t\t\treturn annotation;\n\t\t\t}\n\t\t}\n\t\treturn null;\n\t}\n\n\t/**","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/paascloud/paascloud-master/blob/781281a9503332ed3cef44ea618349d14230a127/paascloud-common/paascloud-common-core/src/main/java/com/paascloud/core/aspect/BindingResultAop.java#L56-L92","documentation":"BindingResultAop.doAfter inspects controller method arguments for a Spring BindingResult after @Valid binding; if the binding result contains field errors, it throws IllegalArgumentException with the first field error's default message. This converts bean-validation failures (e.g. @NotBlank/@Size violations) into a plain runtime exception surfaced by the aspect.","triggerScenarios":"A request body or form parameter fails JSR-303 validation (e.g. @NotNull, @Length exceeded) on a controller method intercepted by this aspect, so bindingResult.hasErrors() is true.","commonSituations":"Clients POSTing missing required fields, fields over max length, malformed numbers/dates, or API version changes that relaxed/tightened validation annotations.","solutions":["Fix the client payload so it satisfies the validation annotations on the DTO.","Read the message (first field error's defaultMessage) to identify which field violated which constraint.","If the message is unhelpfully generic, replace the DTO's default constraint messages with explicit ones, or use @Validated with a global @ControllerAdvice exception handler."],"exampleFix":"// before\npublic Result create(@RequestBody @Valid UserDto dto, BindingResult bindingResult) { ... }\n// after — rely on the aspect, but give the constraint a clear message\n@NotBlank(message = \"userName must not be blank\")\nprivate String userName;","handlingStrategy":"try-catch","validationCode":"// client side\nif (!dto.userName || dto.userName.length > 20) {\n    showFieldError(\"userName invalid\");\n    return;\n}","typeGuard":null,"tryCatchPattern":"try {\n    ResponseEntity<Result> r = restTemplate.postForEntity(url, req, Result.class);\n} catch (IllegalArgumentException e) {\n    // message is the first field error's defaultMessage\n    renderValidationError(e.getMessage());\n}","preventionTips":["Keep DTO constraint messages explicit (message attribute) so the surfaced defaultMessage is actionable.","Validate on the client before submitting to avoid round-trip failures.","Add a global exception handler mapping IllegalArgumentException to a 400 response."],"tags":["validation","spring","bean-validation","aop"],"backgroundTag":"schema-validation-failed","analyzedSha":"781281a9503332ed3cef44ea618349d14230a127","analyzedAt":"2026-09-10T10:59:02.070Z","contentChangedAt":"2026-09-10T10:59:02.070Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}