From 94f0976fd87969a78cd9cbe32800f3d3a8b09ddd Mon Sep 17 00:00:00 2001 From: StefanSpieker Date: Sat, 21 Dec 2019 13:49:41 +0100 Subject: [PATCH] Spotbugs findings (catch runtime ex. and known null) (#4380) * refactor exception to actually put the failing string inside instead of null * do not catch RuntimeExceptions --- core/src/main/java/hudson/model/UpdateCenter.java | 4 +++- core/src/main/java/hudson/scheduler/CronTabList.java | 5 +++-- core/src/main/java/hudson/util/DoubleLaunchChecker.java | 4 +++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/hudson/model/UpdateCenter.java b/core/src/main/java/hudson/model/UpdateCenter.java index a6440b5669..0ea9f6ef80 100644 --- a/core/src/main/java/hudson/model/UpdateCenter.java +++ b/core/src/main/java/hudson/model/UpdateCenter.java @@ -980,8 +980,10 @@ public class UpdateCenter extends AbstractModelObject implements Saveable, OnMas if (category==null) return Messages.UpdateCenter_PluginCategory_misc(); try { - return (String)Messages.class.getMethod( + return (String) Messages.class.getMethod( "UpdateCenter_PluginCategory_" + category.replace('-', '_')).invoke(null); + } catch (RuntimeException ex) { + throw ex; } catch (Exception ex) { return Messages.UpdateCenter_PluginCategory_unrecognized(category); } diff --git a/core/src/main/java/hudson/scheduler/CronTabList.java b/core/src/main/java/hudson/scheduler/CronTabList.java index eba4f007f8..edeb6e0a37 100644 --- a/core/src/main/java/hudson/scheduler/CronTabList.java +++ b/core/src/main/java/hudson/scheduler/CronTabList.java @@ -106,11 +106,12 @@ public final class CronTabList { line = line.trim(); if(lineNumber == 1 && line.startsWith("TZ=")) { - timezone = getValidTimezone(line.replace("TZ=","")); + final String timezoneString = line.replace("TZ=", ""); + timezone = getValidTimezone(timezoneString); if(timezone != null) { LOGGER.log(Level.CONFIG, "CRON with timezone {0}", timezone); } else { - throw new ANTLRException("Invalid or unsupported timezone '" + timezone + "'"); + throw new ANTLRException("Invalid or unsupported timezone '" + timezoneString + "'"); } continue; } diff --git a/core/src/main/java/hudson/util/DoubleLaunchChecker.java b/core/src/main/java/hudson/util/DoubleLaunchChecker.java index 74c4c59933..2bf43010fa 100644 --- a/core/src/main/java/hudson/util/DoubleLaunchChecker.java +++ b/core/src/main/java/hudson/util/DoubleLaunchChecker.java @@ -133,7 +133,9 @@ public class DoubleLaunchChecker { String contextPath=""; try { Method m = ServletContext.class.getMethod("getContextPath"); - contextPath=" contextPath=\""+m.invoke(h.servletContext)+"\""; + contextPath = " contextPath=\"" + m.invoke(h.servletContext) + "\""; + } catch (RuntimeException e) { + throw e; } catch (Exception e) { // maybe running with Servlet 2.4 } -- GitLab