hs-web/hsweb-framework · warning · NullPointerException
e.getMessage()
Error message
e.getMessage()
What it means
In the servlet (WebMvc) variant of the error advice, IllegalArgumentException is mapped to HTTP 400 with code illegal_argument and a message resolved via resolveMessage(e) — which tries to localize e.getMessage(). The 'e.getMessage()' placeholder indicates the raw IllegalArgumentException text is what a client normally sees when no localized key matches. This fires for argument-validation failures inside MVC controllers/services.
Solutions
- Fix the caller to supply the required argument/value described in the exception message.
- Validate inputs at the edge with @Valid/@NotNull or explicit checks so users get field-level 400 errors.
- Use a localized message key as the IllegalArgumentException text so resolveMessage(e) yields a translatable message.
- Prefer dedicated exceptions (NotFoundException, ForbiddenException) for non-argument failures to get correct HTTP codes.
Example fix
// before
throw new IllegalArgumentException("id is null");
// after
throw new IllegalArgumentException("error.id_not_null"); // resolvable via i18n bundle Defensive patterns
Strategy: validation
Validate before calling
// Java caller-side check mirroring server expectations
if (id == null || id.isEmpty()) {
throw new IllegalArgumentException("error.id_required");
} Try / catch
try {
return controller.handle(param);
} catch (IllegalArgumentException e) {
return ResponseMessage.error(400, "illegal_argument",
LocaleUtils.resolveMessage(e.getMessage(), e.getMessage()));
} Prevention
- Use @Valid/@Validated and bean-validation annotations on DTOs.
- Use i18n message keys as IllegalArgumentException messages.
- Check term/query DSL strings against documented formats before sending.
- Cover validation branches with unit tests.
When it happens
Trigger: A controller/service calls e.g. Assert/Assert.notNull, StringUtils checks, or throws new IllegalArgumentException("...") for bad request parameters in a Spring MVC (non-WebFlux) deployment, reaching the handleException(IllegalArgumentException) at line 180.
Common situations: Missing or malformed query/body parameters; hsweb dynamic-query term strings with bad syntax (like the DimensionTerm error); programmatic validation in service layer; enum parsing of user input.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- parentId
- join class [" + clazz + "] not found!
- join alias [" + alias + "] not found!
- error.page_size_exceeded
- valuesList[" + valuesList + "] must have alias
AI-assisted analysis of hs-web/hsweb-framework@b2cfc85a57 (2026-09-13).
Data as JSON: /api/errors/7de04b49413b4c6b.
Report an issue: GitHub.
Appendix: source
Thrown at hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/web/CommonWebMvcErrorControllerAdvice.java:180
@Order
public ResponseMessage<Object> handleException(HttpMessageNotReadableException e) {
return ResponseMessage
.error(400,
"missing_request_body",
LocaleUtils.resolveMessage("error.missing_request_body"));
}
@ExceptionHandler
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ResponseMessage<Object> handleException(NullPointerException e) {
log.warn(e.getLocalizedMessage(), e);
return ResponseMessage.error(e.getMessage());
}
@ExceptionHandler
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ResponseMessage<Object> handleException(IllegalArgumentException e) {
log.warn(e.getLocalizedMessage(), e);
return ResponseMessage.error(400, CodeConstants.Error.illegal_argument, resolveMessage(e));
}
@ExceptionHandler
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ResponseMessage<Object> handleException(AuthenticationException e) {
log.warn(e.getLocalizedMessage(), e);
return ResponseMessage.error(400, e.getCode(), resolveMessage(e));
}
@ExceptionHandler
@ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE)
public ResponseMessage<Object> handleException(UnsupportedMediaTypeStatusException e) {
log.warn(e.getLocalizedMessage(), e);
return ResponseMessageView on GitHub (pinned to b2cfc85a57)