Jetty: backport patch from 9.4.4 to 9.2.21

to fix Timer crash in RolloverFileOutputStream
1e46576bf4
https://github.com/eclipse/jetty.project/issues/1469
This commit is contained in:
zzz
2017-04-29 14:28:30 +00:00
parent 925caccb57
commit 3dbbc2943f

View File

@ -62,6 +62,8 @@ public class RolloverFileOutputStream extends FilterOutputStream
private boolean _append; private boolean _append;
private int _retainDays; private int _retainDays;
private final TimeZone _zone;
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/** /**
* @param filename The filename must include the string "yyyy_mm_dd", * @param filename The filename must include the string "yyyy_mm_dd",
@ -166,27 +168,28 @@ public class RolloverFileOutputStream extends FilterOutputStream
_retainDays=retainDays; _retainDays=retainDays;
setFile(); setFile();
_zone = zone;
synchronized(RolloverFileOutputStream.class) synchronized(RolloverFileOutputStream.class)
{ {
if (__rollover==null) if (__rollover==null)
__rollover=new Timer(RolloverFileOutputStream.class.getName(),true); __rollover=new Timer(RolloverFileOutputStream.class.getName(),true);
_rollTask=new RollTask();
midnight = Calendar.getInstance();
midnight.setTimeZone(zone);
// set to midnight
midnight.set(Calendar.HOUR, 0);
midnight.set(Calendar.MINUTE, 0);
midnight.set(Calendar.SECOND, 0);
midnight.set(Calendar.MILLISECOND, 0);
scheduleNextRollover(); scheduleNextRollover();
} }
} }
private void scheduleNextRollover() private void scheduleNextRollover()
{ {
_rollTask=new RollTask();
midnight = Calendar.getInstance();
midnight.setTimeZone(_zone);
// set to midnight
midnight.set(Calendar.HOUR, 0);
midnight.set(Calendar.MINUTE, 0);
midnight.set(Calendar.SECOND, 0);
midnight.set(Calendar.MILLISECOND, 0);
// Increment to next day. // Increment to next day.
// Using Calendar.add(DAY, 1) takes in account Daylights Savings // Using Calendar.add(DAY, 1) takes in account Daylights Savings
// differences, and still maintains the "midnight" settings for // differences, and still maintains the "midnight" settings for
@ -322,7 +325,10 @@ public class RolloverFileOutputStream extends FilterOutputStream
_file=null; _file=null;
} }
_rollTask.cancel(); if (_rollTask != null)
{
_rollTask.cancel();
}
} }
} }
@ -338,10 +344,10 @@ public class RolloverFileOutputStream extends FilterOutputStream
RolloverFileOutputStream.this.scheduleNextRollover(); RolloverFileOutputStream.this.scheduleNextRollover();
RolloverFileOutputStream.this.removeOldFiles(); RolloverFileOutputStream.this.removeOldFiles();
} }
catch(IOException e) catch(Throwable t)
{ {
// Cannot log this exception to a LOG, as RolloverFOS can be used by logging // Cannot log this exception to a LOG, as RolloverFOS can be used by logging
e.printStackTrace(System.err); t.printStackTrace(System.err);
} }
} }
} }