From ae328a6588b5f8c50f48cb18d904bf1fe35c9493 Mon Sep 17 00:00:00 2001 From: Rafael da Fonseca Date: Sun, 14 Jun 2015 23:00:27 +0200 Subject: [PATCH] Fix 2 findbugs STCAL_STATIC_SIMPLE_DATE_FORMAT_INSTANCE warnings in BaseCmd.java Dateformat objects are not threadsafe and should be defined as instance variables Both INPUT_FORMAT and NEW_INPUT_FORMAT are only used in ParamProcessWorker.java and doesn't makes it more readable to declare in own class Add missing import statement Removed extraneous file Signed-off-by: Daan Hoogland This closes #457 --- api/src/org/apache/cloudstack/api/BaseCmd.java | 2 -- .../src/com/cloud/api/dispatch/ParamProcessWorker.java | 9 ++++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/api/src/org/apache/cloudstack/api/BaseCmd.java b/api/src/org/apache/cloudstack/api/BaseCmd.java index 12265665d30..ad3a88c2749 100644 --- a/api/src/org/apache/cloudstack/api/BaseCmd.java +++ b/api/src/org/apache/cloudstack/api/BaseCmd.java @@ -87,8 +87,6 @@ public abstract class BaseCmd { private static final Logger s_logger = Logger.getLogger(BaseCmd.class.getName()); public static final String RESPONSE_TYPE_XML = HttpUtils.RESPONSE_TYPE_XML; public static final String RESPONSE_TYPE_JSON = HttpUtils.RESPONSE_TYPE_JSON; - public static final DateFormat INPUT_FORMAT = new SimpleDateFormat("yyyy-MM-dd"); - public static final DateFormat NEW_INPUT_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); public static final String USER_ERROR_MESSAGE = "Internal error executing command, please contact your system administrator"; public static Pattern newInputDateFormat = Pattern.compile("[\\d]+-[\\d]+-[\\d]+ [\\d]+:[\\d]+:[\\d]+"); private static final DateFormat s_outputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); diff --git a/server/src/com/cloud/api/dispatch/ParamProcessWorker.java b/server/src/com/cloud/api/dispatch/ParamProcessWorker.java index b990d4aedf4..eb3b77a5fa5 100644 --- a/server/src/com/cloud/api/dispatch/ParamProcessWorker.java +++ b/server/src/com/cloud/api/dispatch/ParamProcessWorker.java @@ -30,6 +30,7 @@ import java.util.List; import java.util.Map; import java.util.StringTokenizer; import java.util.regex.Matcher; +import java.text.SimpleDateFormat; import javax.inject.Inject; @@ -66,6 +67,8 @@ import com.cloud.utils.exception.CloudRuntimeException; public class ParamProcessWorker implements DispatchWorker { private static final Logger s_logger = Logger.getLogger(ParamProcessWorker.class.getName()); + public final DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd"); + public final DateFormat newInputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); @Inject protected AccountManager _accountMgr; @@ -259,12 +262,12 @@ public class ParamProcessWorker implements DispatchWorker { cmdObj instanceof ArchiveAlertsCmd || cmdObj instanceof DeleteAlertsCmd || cmdObj instanceof GetUsageRecordsCmd) { final boolean isObjInNewDateFormat = isObjInNewDateFormat(paramObj.toString()); if (isObjInNewDateFormat) { - final DateFormat newFormat = BaseCmd.NEW_INPUT_FORMAT; + final DateFormat newFormat = newInputFormat; synchronized (newFormat) { field.set(cmdObj, newFormat.parse(paramObj.toString())); } } else { - final DateFormat format = BaseCmd.INPUT_FORMAT; + final DateFormat format = inputFormat; synchronized (format) { Date date = format.parse(paramObj.toString()); if (field.getName().equals("startDate")) { @@ -276,7 +279,7 @@ public class ParamProcessWorker implements DispatchWorker { } } } else { - final DateFormat format = BaseCmd.INPUT_FORMAT; + final DateFormat format = inputFormat; synchronized (format) { format.setLenient(false); field.set(cmdObj, format.parse(paramObj.toString()));