From 4493561e9a81888830cbe7848acf62e04b272cff Mon Sep 17 00:00:00 2001 From: HoussemNasri Date: Sat, 16 Sep 2023 03:44:06 +0100 Subject: [PATCH 1/4] Fix NoClassDefFoundError when opening notifications --- .../rhn/domain/notification/UserNotificationFactory.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/java/code/src/com/redhat/rhn/domain/notification/UserNotificationFactory.java b/java/code/src/com/redhat/rhn/domain/notification/UserNotificationFactory.java index 148b5bf7ec19..b4237388afeb 100644 --- a/java/code/src/com/redhat/rhn/domain/notification/UserNotificationFactory.java +++ b/java/code/src/com/redhat/rhn/domain/notification/UserNotificationFactory.java @@ -77,7 +77,8 @@ private static void configureMailer() { Class cobj = Class.forName(clazz).asSubclass(Mail.class); mailer = cobj.getDeclaredConstructor().newInstance(); } - catch (Exception e) { + catch (Throwable e) { + log.warn("An exception was thrown while configuring Mailer", e); mailer = new SmtpMail(); } } From 7643a9282c4546374e0cacd71ad9c78e2f690017 Mon Sep 17 00:00:00 2001 From: HoussemNasri Date: Sun, 17 Sep 2023 20:40:11 +0100 Subject: [PATCH 2/4] Update Changelog --- java/spacewalk-java.changes.houssemnasri.fix-notification-error | 1 + 1 file changed, 1 insertion(+) create mode 100644 java/spacewalk-java.changes.houssemnasri.fix-notification-error diff --git a/java/spacewalk-java.changes.houssemnasri.fix-notification-error b/java/spacewalk-java.changes.houssemnasri.fix-notification-error new file mode 100644 index 000000000000..8bf7f70b9b3d --- /dev/null +++ b/java/spacewalk-java.changes.houssemnasri.fix-notification-error @@ -0,0 +1 @@ +- Fix server error when visiting the notifications page From f15265bd7c72750c1463b5503d1860e2fe15c80d Mon Sep 17 00:00:00 2001 From: HoussemNasri Date: Tue, 19 Sep 2023 13:42:55 +0100 Subject: [PATCH 3/4] Fix similar error that can be caused by an invalid custom mailer class --- .../domain/notification/UserNotificationFactory.java | 2 +- .../com/redhat/rhn/frontend/events/BaseMailAction.java | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/java/code/src/com/redhat/rhn/domain/notification/UserNotificationFactory.java b/java/code/src/com/redhat/rhn/domain/notification/UserNotificationFactory.java index b4237388afeb..c19ad53a8c94 100644 --- a/java/code/src/com/redhat/rhn/domain/notification/UserNotificationFactory.java +++ b/java/code/src/com/redhat/rhn/domain/notification/UserNotificationFactory.java @@ -78,7 +78,7 @@ private static void configureMailer() { mailer = cobj.getDeclaredConstructor().newInstance(); } catch (Throwable e) { - log.warn("An exception was thrown while configuring Mailer", e); + log.error("An exception was thrown while initializing custom mailer class", e); mailer = new SmtpMail(); } } diff --git a/java/code/src/com/redhat/rhn/frontend/events/BaseMailAction.java b/java/code/src/com/redhat/rhn/frontend/events/BaseMailAction.java index efa61a5c1e91..f5a8bf3fe6b5 100644 --- a/java/code/src/com/redhat/rhn/frontend/events/BaseMailAction.java +++ b/java/code/src/com/redhat/rhn/frontend/events/BaseMailAction.java @@ -52,16 +52,16 @@ public void execute(EventMessage msg) { * @return the mailer associated with this class */ protected Mail getMail() { - String clazz = Config.get().getString( - "web.mailer_class"); + String clazz = Config.get().getString("web.mailer_class"); if (clazz == null) { return new SmtpMail(); } try { - Class cobj = Class.forName(clazz); - return (Mail) cobj.newInstance(); + Class cobj = Class.forName(clazz).asSubclass(Mail.class); + return cobj.getDeclaredConstructor().newInstance(); } - catch (Exception e) { + catch (Throwable e) { + getLogger().error("An exception was thrown while initializing custom mailer class", e); return new SmtpMail(); } } From 3ab18e763c25a859c53a1115bf011f5753c452ad Mon Sep 17 00:00:00 2001 From: HoussemNasri Date: Sun, 24 Sep 2023 21:48:29 +0100 Subject: [PATCH 4/4] Fix Sonarcloud issues --- .../redhat/rhn/domain/notification/UserNotificationFactory.java | 2 +- .../code/src/com/redhat/rhn/frontend/events/BaseMailAction.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/java/code/src/com/redhat/rhn/domain/notification/UserNotificationFactory.java b/java/code/src/com/redhat/rhn/domain/notification/UserNotificationFactory.java index c19ad53a8c94..4673a8240fff 100644 --- a/java/code/src/com/redhat/rhn/domain/notification/UserNotificationFactory.java +++ b/java/code/src/com/redhat/rhn/domain/notification/UserNotificationFactory.java @@ -77,7 +77,7 @@ private static void configureMailer() { Class cobj = Class.forName(clazz).asSubclass(Mail.class); mailer = cobj.getDeclaredConstructor().newInstance(); } - catch (Throwable e) { + catch (Exception | LinkageError e) { log.error("An exception was thrown while initializing custom mailer class", e); mailer = new SmtpMail(); } diff --git a/java/code/src/com/redhat/rhn/frontend/events/BaseMailAction.java b/java/code/src/com/redhat/rhn/frontend/events/BaseMailAction.java index f5a8bf3fe6b5..8a8c9f73f12c 100644 --- a/java/code/src/com/redhat/rhn/frontend/events/BaseMailAction.java +++ b/java/code/src/com/redhat/rhn/frontend/events/BaseMailAction.java @@ -60,7 +60,7 @@ protected Mail getMail() { Class cobj = Class.forName(clazz).asSubclass(Mail.class); return cobj.getDeclaredConstructor().newInstance(); } - catch (Throwable e) { + catch (Exception | LinkageError e) { getLogger().error("An exception was thrown while initializing custom mailer class", e); return new SmtpMail(); }