fix proposed by Jacks - synchronizing SimpleDateFormat

This commit is contained in:
Jeremy Long
2016-12-03 17:41:32 -05:00
parent 0202bc11d4
commit 1474855305

View File

@@ -41,21 +41,24 @@ public class DatabaseProperties {
*/ */
private static final Logger LOGGER = LoggerFactory.getLogger(DatabaseProperties.class); private static final Logger LOGGER = LoggerFactory.getLogger(DatabaseProperties.class);
/** /**
* Modified key word, used as a key to store information about the modified file (i.e. the containing the last 8 days of * Modified key word, used as a key to store information about the modified
* updates).. * file (i.e. the containing the last 8 days of updates)..
*/ */
public static final String MODIFIED = "Modified"; public static final String MODIFIED = "Modified";
/** /**
* The properties file key for the last checked field - used to store the last check time of the Modified NVD CVE xml file. * The properties file key for the last checked field - used to store the
* last check time of the Modified NVD CVE xml file.
*/ */
public static final String LAST_CHECKED = "NVD CVE Checked"; public static final String LAST_CHECKED = "NVD CVE Checked";
/** /**
* The properties file key for the last updated field - used to store the last updated time of the Modified NVD CVE xml file. * The properties file key for the last updated field - used to store the
* last updated time of the Modified NVD CVE xml file.
*/ */
public static final String LAST_UPDATED = "NVD CVE Modified"; public static final String LAST_UPDATED = "NVD CVE Modified";
/** /**
* Stores the last updated time for each of the NVD CVE files. These timestamps should be updated if we process the modified * Stores the last updated time for each of the NVD CVE files. These
* file within 7 days of the last update. * timestamps should be updated if we process the modified file within 7
* days of the last update.
*/ */
public static final String LAST_UPDATED_BASE = "NVD CVE "; public static final String LAST_UPDATED_BASE = "NVD CVE ";
/** /**
@@ -121,7 +124,8 @@ public class DatabaseProperties {
} }
/** /**
* Returns the property value for the given key. If the key is not contained in the underlying properties null is returned. * Returns the property value for the given key. If the key is not contained
* in the underlying properties null is returned.
* *
* @param key the property key * @param key the property key
* @return the value of the property * @return the value of the property
@@ -131,8 +135,8 @@ public class DatabaseProperties {
} }
/** /**
* Returns the property value for the given key. If the key is not contained in the underlying properties the default value is * Returns the property value for the given key. If the key is not contained
* returned. * in the underlying properties the default value is returned.
* *
* @param key the property key * @param key the property key
* @param defaultValue the default value * @param defaultValue the default value
@@ -152,8 +156,9 @@ public class DatabaseProperties {
} }
/** /**
* Returns a map of the meta data from the database properties. This primarily contains timestamps of when the NVD CVE * Returns a map of the meta data from the database properties. This
* information was last updated. * primarily contains timestamps of when the NVD CVE information was last
* updated.
* *
* @return a map of the database meta data * @return a map of the database meta data
*/ */
@@ -166,9 +171,11 @@ public class DatabaseProperties {
try { try {
final long epoch = Long.parseLong((String) entry.getValue()); final long epoch = Long.parseLong((String) entry.getValue());
final Date date = new Date(epoch); final Date date = new Date(epoch);
final DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); synchronized (date) {
final String formatted = format.format(date); final DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
map.put(key, formatted); final String formatted = format.format(date);
map.put(key, formatted);
}
} catch (Throwable ex) { //deliberately being broad in this catch clause } catch (Throwable ex) { //deliberately being broad in this catch clause
LOGGER.debug("Unable to parse timestamp from DB", ex); LOGGER.debug("Unable to parse timestamp from DB", ex);
map.put(key, (String) entry.getValue()); map.put(key, (String) entry.getValue());