-
Notifications
You must be signed in to change notification settings - Fork 3
fix: graceful degradation when plugin not found #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -323,13 +323,19 @@ INSERT INTO mailbox_users (uuid, user_data, address) VALUES (?, ?, ?) | |||||||||||||||||||||||||||||||||
| UUID id = UUID.fromString(rs.getString("id")); | ||||||||||||||||||||||||||||||||||
| UUID senderId = Optional.ofNullable(rs.getString("sender")).map(UUID::fromString).orElse(DummyMailUser.SYSTEM_UUID); | ||||||||||||||||||||||||||||||||||
| User sender = getUser(senderId); | ||||||||||||||||||||||||||||||||||
| if (sender == null) { | ||||||||||||||||||||||||||||||||||
| sender = DummyMailUser.createUser(senderId, "Unknown Sender", "unknown", null); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| UUID receiverId = UUID.fromString(rs.getString("receiver")); | ||||||||||||||||||||||||||||||||||
| User receiver = getUser(receiverId); | ||||||||||||||||||||||||||||||||||
| if (receiver == null) { | ||||||||||||||||||||||||||||||||||
| receiver = DummyMailUser.createUser(receiverId, "Unknown Receiver", "unknown", null); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+326
to
+333
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using a hardcoded key value of Why this is an issue:
Solution:Use the user's unique UUID string (e.g.,
Suggested change
|
||||||||||||||||||||||||||||||||||
| String title = rs.getString("title"); | ||||||||||||||||||||||||||||||||||
| String content = rs.getString("content"); | ||||||||||||||||||||||||||||||||||
| boolean isRead = rs.getBoolean("is_read"); | ||||||||||||||||||||||||||||||||||
| LocalDateTime sentTime = rs.getTimestamp("sentTime").toLocalDateTime(); | ||||||||||||||||||||||||||||||||||
| Mail mail = new Mail(id, Objects.requireNonNull(sender), Objects.requireNonNull(receiver), title, content, List.of(), isRead, sentTime); | ||||||||||||||||||||||||||||||||||
| Mail mail = new Mail(id, sender, receiver, title, content, List.of(), isRead, sentTime); | ||||||||||||||||||||||||||||||||||
| mail.attachments(getMailAttachments(mail)); | ||||||||||||||||||||||||||||||||||
| mails.add(mail); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
@@ -344,13 +350,19 @@ INSERT INTO mailbox_users (uuid, user_data, address) VALUES (?, ?, ?) | |||||||||||||||||||||||||||||||||
| UUID id = UUID.fromString(rs.getString("id")); | ||||||||||||||||||||||||||||||||||
| UUID senderId = Optional.ofNullable(rs.getString("sender")).map(UUID::fromString).orElse(DummyMailUser.SYSTEM_UUID); | ||||||||||||||||||||||||||||||||||
| User sender = getUser(senderId); | ||||||||||||||||||||||||||||||||||
| if (sender == null) { | ||||||||||||||||||||||||||||||||||
| sender = DummyMailUser.createUser(senderId, "Unknown Sender", "unknown", null); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| UUID receiverId = UUID.fromString(rs.getString("receiver")); | ||||||||||||||||||||||||||||||||||
| User receiver = getUser(receiverId); | ||||||||||||||||||||||||||||||||||
| if (receiver == null) { | ||||||||||||||||||||||||||||||||||
| receiver = DummyMailUser.createUser(receiverId, "Unknown Receiver", "unknown", null); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+353
to
+360
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using a hardcoded key value of
Suggested change
|
||||||||||||||||||||||||||||||||||
| String title = rs.getString("title"); | ||||||||||||||||||||||||||||||||||
| String content = rs.getString("content"); | ||||||||||||||||||||||||||||||||||
| boolean isRead = rs.getBoolean("is_read"); | ||||||||||||||||||||||||||||||||||
| LocalDateTime sentTime = rs.getTimestamp("sentTime").toLocalDateTime(); | ||||||||||||||||||||||||||||||||||
| Mail mail = new Mail(id, Objects.requireNonNull(sender), Objects.requireNonNull(receiver), title, content, List.of(), isRead, sentTime); | ||||||||||||||||||||||||||||||||||
| Mail mail = new Mail(id, sender, receiver, title, content, List.of(), isRead, sentTime); | ||||||||||||||||||||||||||||||||||
| mail.attachments(getMailAttachments(mail)); | ||||||||||||||||||||||||||||||||||
| mails.add(mail); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
@@ -396,13 +408,19 @@ public int countMails(@NotNull User user, @NotNull TriState read) { | |||||||||||||||||||||||||||||||||
| if (rs.next()) { | ||||||||||||||||||||||||||||||||||
| UUID senderId = Optional.ofNullable(rs.getString("sender")).map(UUID::fromString).orElse(DummyMailUser.SYSTEM_UUID); | ||||||||||||||||||||||||||||||||||
| User sender = getUser(senderId); | ||||||||||||||||||||||||||||||||||
| if (sender == null) { | ||||||||||||||||||||||||||||||||||
| sender = DummyMailUser.createUser(senderId, "Unknown Sender", "unknown", null); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| UUID receiverId = UUID.fromString(rs.getString("receiver")); | ||||||||||||||||||||||||||||||||||
| User receiver = getUser(receiverId); | ||||||||||||||||||||||||||||||||||
| if (receiver == null) { | ||||||||||||||||||||||||||||||||||
| receiver = DummyMailUser.createUser(receiverId, "Unknown Receiver", "unknown", null); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+411
to
+418
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using a hardcoded key value of
Suggested change
|
||||||||||||||||||||||||||||||||||
| String title = rs.getString("title"); | ||||||||||||||||||||||||||||||||||
| String content = rs.getString("content"); | ||||||||||||||||||||||||||||||||||
| boolean read = rs.getBoolean("is_read"); | ||||||||||||||||||||||||||||||||||
| LocalDateTime sentTime = rs.getTimestamp("sentTime").toLocalDateTime(); | ||||||||||||||||||||||||||||||||||
| Mail mail = new Mail(id, Objects.requireNonNull(sender), Objects.requireNonNull(receiver), title, content, List.of(), read, sentTime); | ||||||||||||||||||||||||||||||||||
| Mail mail = new Mail(id, sender, receiver, title, content, List.of(), read, sentTime); | ||||||||||||||||||||||||||||||||||
| mail.attachments(getMailAttachments(mail)); | ||||||||||||||||||||||||||||||||||
| return mail; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
@@ -490,11 +508,14 @@ public void updateMailTemplate(@NotNull MailTemplate template) { | |||||||||||||||||||||||||||||||||
| boolean autoSend = rs.getBoolean("auto_send"); | ||||||||||||||||||||||||||||||||||
| UUID senderId = Optional.ofNullable(rs.getString("sender")).map(UUID::fromString).orElse(null); | ||||||||||||||||||||||||||||||||||
| User sender = getUser(senderId); | ||||||||||||||||||||||||||||||||||
| if (sender == null) { | ||||||||||||||||||||||||||||||||||
| sender = DummyMailUser.createUser(senderId != null ? senderId : DummyMailUser.SYSTEM_UUID, "Unknown Sender", "unknown", null); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+511
to
+513
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using a hardcoded key value of
Suggested change
|
||||||||||||||||||||||||||||||||||
| Date startTime = rs.getTimestamp("start_time"); | ||||||||||||||||||||||||||||||||||
| Date endTime = rs.getTimestamp("end_time"); | ||||||||||||||||||||||||||||||||||
| Duration interval = Optional.of(rs.getLong("send_interval")).filter(l -> l > 0).map(Duration::ofSeconds).orElse(null); | ||||||||||||||||||||||||||||||||||
| String permission = rs.getString("permission"); | ||||||||||||||||||||||||||||||||||
| MailTemplate template = new MailTemplate(id, title, content, List.of(), autoSend, Objects.requireNonNull(sender), LocalDateTime.ofInstant(startTime.toInstant(), ZoneId.systemDefault()), LocalDateTime.ofInstant(endTime.toInstant(), ZoneId.systemDefault()), interval, permission); | ||||||||||||||||||||||||||||||||||
| MailTemplate template = new MailTemplate(id, title, content, List.of(), autoSend, sender, LocalDateTime.ofInstant(startTime.toInstant(), ZoneId.systemDefault()), LocalDateTime.ofInstant(endTime.toInstant(), ZoneId.systemDefault()), interval, permission); | ||||||||||||||||||||||||||||||||||
| template.setAttachment(getTemplateAttachments(template)); | ||||||||||||||||||||||||||||||||||
| return template; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
@@ -520,11 +541,14 @@ public void updateMailTemplate(@NotNull MailTemplate template) { | |||||||||||||||||||||||||||||||||
| boolean autoSend = rs.getBoolean("auto_send"); | ||||||||||||||||||||||||||||||||||
| UUID senderId = Optional.ofNullable(rs.getString("sender")).map(UUID::fromString).orElse(null); | ||||||||||||||||||||||||||||||||||
| User sender = getUser(senderId); | ||||||||||||||||||||||||||||||||||
| if (sender == null) { | ||||||||||||||||||||||||||||||||||
| sender = DummyMailUser.createUser(senderId != null ? senderId : DummyMailUser.SYSTEM_UUID, "Unknown Sender", "unknown", null); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+544
to
+546
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using a hardcoded key value of
Suggested change
|
||||||||||||||||||||||||||||||||||
| @Nullable LocalDateTime startTime = Optional.ofNullable(rs.getTimestamp("start_time")).map(timestamp -> LocalDateTime.ofInstant(timestamp.toInstant(), ZoneId.systemDefault())).orElse(null); | ||||||||||||||||||||||||||||||||||
| @Nullable LocalDateTime endTime = Optional.ofNullable(rs.getTimestamp("end_time")).map(timestamp -> LocalDateTime.ofInstant(timestamp.toInstant(), ZoneId.systemDefault())).orElse(null); | ||||||||||||||||||||||||||||||||||
| @Nullable Duration interval = Optional.of(rs.getLong("send_interval")).filter(l -> l > 0).map(Duration::ofSeconds).orElse(null); | ||||||||||||||||||||||||||||||||||
| @Nullable String permission = rs.getString("permission"); | ||||||||||||||||||||||||||||||||||
| MailTemplate template = new MailTemplate(id, title, content, List.of(), autoSend, Objects.requireNonNull(sender), startTime, endTime, interval, permission); | ||||||||||||||||||||||||||||||||||
| MailTemplate template = new MailTemplate(id, title, content, List.of(), autoSend, sender, startTime, endTime, interval, permission); | ||||||||||||||||||||||||||||||||||
| template.setAttachment(getTemplateAttachments(template)); | ||||||||||||||||||||||||||||||||||
| templates.add(template); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
@@ -550,11 +574,14 @@ public void updateMailTemplate(@NotNull MailTemplate template) { | |||||||||||||||||||||||||||||||||
| boolean autoSend = rs.getBoolean("auto_send"); | ||||||||||||||||||||||||||||||||||
| UUID senderId = Optional.ofNullable(rs.getString("sender")).map(UUID::fromString).orElse(null); | ||||||||||||||||||||||||||||||||||
| User sender1 = getUser(senderId); | ||||||||||||||||||||||||||||||||||
| if (sender1 == null) { | ||||||||||||||||||||||||||||||||||
| sender1 = DummyMailUser.createUser(senderId != null ? senderId : DummyMailUser.SYSTEM_UUID, "Unknown Sender", "unknown", null); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+577
to
+579
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using a hardcoded key value of
Suggested change
|
||||||||||||||||||||||||||||||||||
| @Nullable LocalDateTime startTime = Optional.ofNullable(rs.getTimestamp("start_time")).map(timestamp -> LocalDateTime.ofInstant(timestamp.toInstant(), ZoneId.systemDefault())).orElse(null); | ||||||||||||||||||||||||||||||||||
| @Nullable LocalDateTime endTime = Optional.ofNullable(rs.getTimestamp("end_time")).map(timestamp -> LocalDateTime.ofInstant(timestamp.toInstant(), ZoneId.systemDefault())).orElse(null); | ||||||||||||||||||||||||||||||||||
| @Nullable Duration interval = Optional.of(rs.getLong("send_interval")).filter(l -> l > 0).map(Duration::ofSeconds).orElse(null); | ||||||||||||||||||||||||||||||||||
| @Nullable String permission = rs.getString("permission"); | ||||||||||||||||||||||||||||||||||
| MailTemplate template = new MailTemplate(id, title, content, List.of(), autoSend, Objects.requireNonNull(sender1), startTime, endTime, interval, permission); | ||||||||||||||||||||||||||||||||||
| MailTemplate template = new MailTemplate(id, title, content, List.of(), autoSend, sender1, startTime, endTime, interval, permission); | ||||||||||||||||||||||||||||||||||
| template.setAttachment(getTemplateAttachments(template)); | ||||||||||||||||||||||||||||||||||
| templates.add(template); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
@@ -580,11 +607,14 @@ public void updateMailTemplate(@NotNull MailTemplate template) { | |||||||||||||||||||||||||||||||||
| boolean autoSend = rs.getBoolean("auto_send"); | ||||||||||||||||||||||||||||||||||
| UUID senderId = Optional.ofNullable(rs.getString("sender")).map(UUID::fromString).orElse(DummyMailUser.SYSTEM_UUID); | ||||||||||||||||||||||||||||||||||
| User sender = getUser(senderId); | ||||||||||||||||||||||||||||||||||
| if (sender == null) { | ||||||||||||||||||||||||||||||||||
| sender = DummyMailUser.createUser(senderId, "Unknown Sender", "unknown", null); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+610
to
+612
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using a hardcoded key value of
Suggested change
|
||||||||||||||||||||||||||||||||||
| @Nullable LocalDateTime startTime = rs.getTimestamp("start_time") == null ? null : LocalDateTime.ofInstant(rs.getTimestamp("start_time").toInstant(), ZoneId.systemDefault()); | ||||||||||||||||||||||||||||||||||
| @Nullable LocalDateTime endTime = rs.getTimestamp("end_time") == null ? null : LocalDateTime.ofInstant(rs.getTimestamp("end_time").toInstant(), ZoneId.systemDefault()); | ||||||||||||||||||||||||||||||||||
| @Nullable Duration interval = Optional.of(rs.getLong("send_interval")).filter(l -> l > 0).map(Duration::ofSeconds).orElse(null); | ||||||||||||||||||||||||||||||||||
| @Nullable String permission = rs.getString("permission"); | ||||||||||||||||||||||||||||||||||
| MailTemplate template = new MailTemplate(id, title, content, List.of(), autoSend, Objects.requireNonNull(sender), startTime, endTime, interval, permission); | ||||||||||||||||||||||||||||||||||
| MailTemplate template = new MailTemplate(id, title, content, List.of(), autoSend, sender, startTime, endTime, interval, permission); | ||||||||||||||||||||||||||||||||||
| template.setAttachment(getTemplateAttachments(template)); | ||||||||||||||||||||||||||||||||||
| templates.add(template); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning
nullfromreadUserwhen a plugin is not found is a great way to handle graceful degradation. However, please note thatBase.getAllUsers()(line 304 inBase.java) directly adds the result ofreadUser(rs)to a list of typeList<@NotNull User>without checking fornull:This will result in
nullelements being added to a list that is contractually specified to contain only non-nullUsers, which can lead to unexpectedNullPointerExceptions downstream when iterating over the list.Recommendation:
Please update
Base.getAllUsers()to filter outnullusers before adding them to the list: