Skip to content

Commit

Permalink
[FIXED JENKINS-29357] Fixed findbugs warnings in DeadlineTimeOutStrat…
Browse files Browse the repository at this point in the history
…egy. Mainly the issue about thread-safeness of SimpleDateFormatter.
  • Loading branch information
ikedam committed Jul 12, 2015
1 parent a70b008 commit 7d5a730
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Expand Up @@ -26,11 +26,11 @@ public class DeadlineTimeOutStrategy extends BuildTimeOutStrategy {

public static final int MINIMUM_DEADLINE_TOLERANCE_IN_MINUTES = 1;

protected static final String DEADLINE_REGEXP = new String("[0-2]?[0-9]:[0-5][0-9](:[0-5][0-9])?");
protected static final String DEADLINE_REGEXP = "[0-2]?[0-9]:[0-5][0-9](:[0-5][0-9])?";

protected static final SimpleDateFormat TIME_LONG_FORMAT = new SimpleDateFormat("H:mm:ss");
protected static final SimpleDateFormat TIME_SHORT_FORMAT = new SimpleDateFormat("H:mm");
protected static final SimpleDateFormat TIMESTAMP_FORMAT = new SimpleDateFormat("yyyy-MM-dd H:mm:ss");
protected static final String TIME_LONG_FORMAT_PATTERN = "H:mm:ss";
protected static final String TIME_SHORT_FORMAT_PATTERN = "H:mm";
protected static final String TIMESTAMP_FORMAT_PATTERN = "yyyy-MM-dd H:mm:ss";

private final String deadlineTime;
private final int deadlineToleranceInMinutes;
Expand Down Expand Up @@ -87,7 +87,7 @@ public long getTimeOut(AbstractBuild<?, ?> build, BuildListener listener) throws
}

listener.getLogger().println(
Messages.DeadlineTimeOutStrategy_NextDeadline(TIMESTAMP_FORMAT.format(deadlineTimestamp
Messages.DeadlineTimeOutStrategy_NextDeadline(new SimpleDateFormat(TIMESTAMP_FORMAT_PATTERN).format(deadlineTimestamp
.getTime())));

return deadlineTimestamp.getTimeInMillis() - now.getTimeInMillis();
Expand All @@ -98,9 +98,9 @@ private static Date parseDeadline(String deadline) throws IllegalArgumentExcepti
if (deadline.matches(DEADLINE_REGEXP)) {
try {
if (deadline.length() > 5) {
return TIME_LONG_FORMAT.parse(deadline);
return new SimpleDateFormat(TIME_LONG_FORMAT_PATTERN).parse(deadline);
} else {
return TIME_SHORT_FORMAT.parse(deadline);
return new SimpleDateFormat(TIME_SHORT_FORMAT_PATTERN).parse(deadline);
}
} catch (ParseException e) {
}
Expand Down
Expand Up @@ -35,6 +35,7 @@
import hudson.plugins.build_timeout.BuildTimeoutWrapperIntegrationTest;
import hudson.plugins.build_timeout.operations.AbortOperation;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;

Expand Down Expand Up @@ -100,6 +101,6 @@ private String getDeadlineTimeFromNow(int offsetInSeconds) {
Calendar deadline = Calendar.getInstance();
deadline.add(Calendar.SECOND, offsetInSeconds);

return DeadlineTimeOutStrategy.TIME_LONG_FORMAT.format(deadline.getTime());
return new SimpleDateFormat(DeadlineTimeOutStrategy.TIME_LONG_FORMAT_PATTERN).format(deadline.getTime());
}
}

0 comments on commit 7d5a730

Please sign in to comment.