forked from I2P_Developers/i2p.i2p
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:
@ -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,9 +325,12 @@ public class RolloverFileOutputStream extends FilterOutputStream
|
|||||||
_file=null;
|
_file=null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_rollTask != null)
|
||||||
|
{
|
||||||
_rollTask.cancel();
|
_rollTask.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
private class RollTask extends TimerTask
|
private class RollTask extends TimerTask
|
||||||
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user