fix(alert): guard against null alert/dateCreated in email alert template - #6457
Open
wy471x wants to merge 1 commit into
Open
fix(alert): guard against null alert/dateCreated in email alert template#6457wy471x wants to merge 1 commit into
wy471x wants to merge 1 commit into
Conversation
wy471x
force-pushed
the
fix_EmailAlertReportFail
branch
from
July 26, 2026 11:53
bb7c523 to
cbe08cf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
Make sure that:
./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
content, plus builder/getter/setter correctness.
dateCreated is null, or content is null.
close #6446