LANG-1152 StringIndexOutOfBoundsException or field over-write for large year fields in FastDateParser

This commit is contained in:
Chas Honton 2015-07-07 21:15:58 -07:00
parent 40134ecdb3
commit 52b46e74dd
3 changed files with 23 additions and 2 deletions

View File

@ -22,6 +22,7 @@
<body> <body>
<release version="3.5" date="tba" description="tba"> <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-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-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> <action issue="LANG-1147" type="fix" dev="sebb" due-to="Loic Guibert">EnumUtils *BitVector issue with more than 32 values Enum</action>

View File

@ -875,14 +875,21 @@ public void appendTo(final StringBuffer buffer, final Calendar calendar) {
*/ */
@Override @Override
public final void appendTo(final StringBuffer buffer, int value) { public final void appendTo(final StringBuffer buffer, int value) {
int first = buffer.length();
// pad the buffer with adequate zeros // pad the buffer with adequate zeros
for(int digit = 0; digit<mSize; ++digit) { for(int digit = 0; digit<mSize; ++digit) {
buffer.append('0'); buffer.append('0');
} }
// backfill the buffer with non-zero digits // backfill the buffer with non-zero digits
int index = buffer.length(); int index = buffer.length();
for( ; value>0; value /= 10) { 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);
}
} }
} }
} }

View File

@ -37,6 +37,7 @@
import org.apache.commons.lang3.test.SystemDefaults; import org.apache.commons.lang3.test.SystemDefaults;
import org.apache.commons.lang3.test.SystemDefaultsSwitch; import org.apache.commons.lang3.test.SystemDefaultsSwitch;
import org.junit.Assert;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@ -291,4 +292,16 @@ public void run() {
assertEquals(0, failures.get()); assertEquals(0, failures.get());
return totalElapsed.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);
}
} }