From 399ff337c8458446496940abf86501ae00d2113c Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 13 Apr 2017 09:07:26 -0700 Subject: [PATCH] Issue #1469 - conforming to java.util.Timer quirks --- .../jetty/util/RolloverFileOutputStream.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/RolloverFileOutputStream.java b/jetty-util/src/main/java/org/eclipse/jetty/util/RolloverFileOutputStream.java index db3b7bec52e..401ccd0aff0 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/RolloverFileOutputStream.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/RolloverFileOutputStream.java @@ -175,8 +175,6 @@ public class RolloverFileOutputStream extends FilterOutputStream if (__rollover==null) __rollover=new Timer(RolloverFileOutputStream.class.getName(),true); - _rollTask=new RollTask(); - midnight = toMidnight(ZonedDateTime.now(), zone.toZoneId()); scheduleNextRollover(); @@ -204,14 +202,12 @@ public class RolloverFileOutputStream extends FilterOutputStream public static ZonedDateTime nextMidnight(ZonedDateTime dateTime) { // Increment to next day. - // Using Calendar.add(DAY, 1) takes in account Daylights Savings - // differences, and still maintains the "midnight" settings for - // Hour, Minute, Second, Milliseconds return dateTime.toLocalDate().plus(1, ChronoUnit.DAYS).atStartOfDay(dateTime.getZone()); } private void scheduleNextRollover() { + _rollTask = new RollTask(); midnight = nextMidnight(midnight); __rollover.schedule(_rollTask,midnight.toInstant().toEpochMilli() - System.currentTimeMillis()); } @@ -342,8 +338,11 @@ public class RolloverFileOutputStream extends FilterOutputStream out=null; _file=null; } - - _rollTask.cancel(); + + if (_rollTask != null) + { + _rollTask.cancel(); + } } } @@ -359,10 +358,10 @@ public class RolloverFileOutputStream extends FilterOutputStream RolloverFileOutputStream.this.scheduleNextRollover(); RolloverFileOutputStream.this.removeOldFiles(); } - catch(IOException e) + catch(Throwable t) { // Cannot log this exception to a LOG, as RolloverFOS can be used by logging - e.printStackTrace(System.err); + t.printStackTrace(System.err); } } }