wy471x opened a new pull request, #6457: URL: https://github.com/apache/shenyu/pull/6457
Move null check before alert dereferencing in EmailAlertNotifyStrategy to prevent NullPointerException. Add @NotBlank validation on AlarmContent title and content fields. Add unit tests for both fixes. <!-- Describe your PR here; e.g. Fixes #issueNo --> <!-- Thank you for proposing a pull request. This template will guide you through the essential steps necessary for a pull request. --> Make sure that: - [X] You have read the [contribution guidelines](https://shenyu.apache.org/community/contributor-guide). - [X] You submit test cases (unit or integration tests) that back your changes. - [X] Your local test passed `./mvnw clean install -Dmaven.javadoc.skip=true`. ## Summary of Changes Bug Fix — EmailAlertNotifyStrategy.java File: shenyu-alert/src/main/java/org/apache/shenyu/alert/strategy/EmailAlertNotifyStrategy.java Moved the null check before any dereferencing of alert. Previously, alert.getContent() and alert.getDateCreated() were called on lines 81-83 while the null guard if (Objects.isNull(alert)) sat dead on line 84. Now both alert == null and dateCreated == null are guarded with safe fallbacks ("" for content, new Date() for date), matching the pattern already used in AbstractAlertNotifyHandler.renderContent(). Bean Validation — AlarmContent.java File: shenyu-common/src/main/java/org/apache/shenyu/common/dto/AlarmContent.java Added @NotBlank constraints on title and content fields. The existing ExceptionHandlers already catches MethodArgumentNotValidException, so invalid requests now get a controlled 400 response instead of an internal error. Dependency — shenyu-common/pom.xml Added jakarta.validation-api (provided scope) since AlarmContent now imports @NotBlank. Unit Tests - AlarmContentTest.java (shenyu-common) — verifies @NotBlank annotations are present on title and content, plus builder/getter/setter correctness. - EmailAlertNotifyStrategyTest.java (shenyu-alert) — verifies no NPE is thrown when alert is null, dateCreated is null, or content is null. close [#6446](https://github.com/apache/shenyu/issues/6446) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
