LANG-1152 StringIndexOutOfBoundsException or field over-write for large year fields in FastDateParser
This commit is contained in:
parent
40134ecdb3
commit
52b46e74dd
|
@ -22,6 +22,7 @@
|
|||
<body>
|
||||
|
||||
<release version="3.5" date="tba" description="tba">
|
||||
<action issue="LANG-1152" type="fix" dev="chas" due-to="Pas Filip">StringIndexOutOfBoundsException or field over-write for large year fields in FastDateParser</action>
|
||||
<action issue="LANG-1153" type="add" dev="chas">Implement ParsePosition api for FastDateParser</action>
|
||||
<action issue="LANG-1141" type="fix" dev="oheger">StrLookup.systemPropertiesLookup() no longer reacts on changes on system properties</action>
|
||||
<action issue="LANG-1147" type="fix" dev="sebb" due-to="Loic Guibert">EnumUtils *BitVector issue with more than 32 values Enum</action>
|
||||
|
|
|
@ -875,6 +875,7 @@ public class FastDatePrinter implements DatePrinter, Serializable {
|
|||
*/
|
||||
@Override
|
||||
public final void appendTo(final StringBuffer buffer, int value) {
|
||||
int first = buffer.length();
|
||||
// pad the buffer with adequate zeros
|
||||
for(int digit = 0; digit<mSize; ++digit) {
|
||||
buffer.append('0');
|
||||
|
@ -882,7 +883,13 @@ public class FastDatePrinter implements DatePrinter, Serializable {
|
|||
// backfill the buffer with non-zero digits
|
||||
int index = buffer.length();
|
||||
for( ; value>0; value /= 10) {
|
||||
buffer.setCharAt(--index, (char)('0' + value % 10));
|
||||
char c= (char)('0' + value % 10);
|
||||
if(--index<first) {
|
||||
buffer.insert(first, c);
|
||||
}
|
||||
else {
|
||||
buffer.setCharAt(index, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ import java.util.concurrent.atomic.AtomicLong;
|
|||
|
||||
import org.apache.commons.lang3.test.SystemDefaults;
|
||||
import org.apache.commons.lang3.test.SystemDefaultsSwitch;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -291,4 +292,16 @@ public class FastDateFormatTest {
|
|||
assertEquals(0, failures.get());
|
||||
return totalElapsed.get();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLANG_1152() {
|
||||
TimeZone utc = TimeZone.getTimeZone("UTC");
|
||||
Date date = new Date(Long.MAX_VALUE);
|
||||
|
||||
String dateAsString = FastDateFormat.getInstance("yyyy-MM-dd", utc, Locale.US).format(date);
|
||||
Assert.assertEquals("292278994-08-17", dateAsString);
|
||||
|
||||
dateAsString = FastDateFormat.getInstance("dd/MM/yyyy", utc, Locale.US).format(date);
|
||||
Assert.assertEquals("17/08/292278994", dateAsString);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue