The failing test cases:
src/test/java/org/joda/time/format/TestDateTimeFormatter.java:866-871
public void testParseInto_monthOnly() {
DateTimeFormatter f = DateTimeFormat.forPattern("M").withLocale(Locale.UK);
MutableDateTime result = new MutableDateTime(2004, 1, 9, 12, 20, 30, 0, LONDON);
assertEquals(1, f.parseInto(result, "5", 0));
assertEquals(new MutableDateTime(2004, 5, 9, 12, 20, 30, 0, LONDON), result); // <-- TC fails here
}
src/test/java/org/joda/time/format/TestDateTimeFormatter.java:873-878
public void testParseInto_monthOnly_baseStartYear() {
DateTimeFormatter f = DateTimeFormat.forPattern("M").withLocale(Locale.UK);
MutableDateTime result = new MutableDateTime(2004, 1, 1, 12, 20, 30, 0, TOKYO);
assertEquals(1, f.parseInto(result, "5", 0));
assertEquals(new MutableDateTime(2004, 5, 1, 12, 20, 30, 0, TOKYO), result); // <-- TC fails here
}
src/test/java/org/joda/time/format/TestDateTimeFormatter.java:880-885
public void testParseInto_monthOnly_parseStartYear() {
DateTimeFormatter f = DateTimeFormat.forPattern("M").withLocale(Locale.UK);
MutableDateTime result = new MutableDateTime(2004, 2, 1, 12, 20, 30, 0, TOKYO);
assertEquals(1, f.parseInto(result, "1", 0));
assertEquals(new MutableDateTime(2004, 1, 1, 12, 20, 30, 0, TOKYO), result); // <-- TC fails here
}
src/test/java/org/joda/time/format/TestDateTimeFormatter.java:887-892
public void testParseInto_monthOnly_baseEndYear() {
DateTimeFormatter f = DateTimeFormat.forPattern("M").withLocale(Locale.UK);
MutableDateTime result = new MutableDateTime(2004, 12, 31, 12, 20, 30, 0, TOKYO);
assertEquals(1, f.parseInto(result, "5", 0));
assertEquals(new MutableDateTime(2004, 5, 31, 12, 20, 30, 0, TOKYO), result); // <-- TC fails here
}
src/test/java/org/joda/time/format/TestDateTimeFormatter.java:894-899
public void testParseInto_monthOnly_parseEndYear() {
DateTimeFormatter f = DateTimeFormat.forPattern("M").withLocale(Locale.UK);
MutableDateTime result = new MutableDateTime(2004, 1, 31, 12, 20, 30, 0,TOKYO);
assertEquals(2, f.parseInto(result, "12", 0));
assertEquals(new MutableDateTime(2004, 12, 31, 12, 20, 30, 0, TOKYO), result); // <-- TC fails here
}
src/test/java/org/joda/time/format/TestDateTimeFormatter.java:901-906
public void testParseInto_monthDay_feb29() {
DateTimeFormatter f = DateTimeFormat.forPattern("M d").withLocale(Locale.UK);
MutableDateTime result = new MutableDateTime(2004, 1, 9, 12, 20, 30, 0, LONDON);
assertEquals(4, f.parseInto(result, "2 29", 0));
assertEquals(new MutableDateTime(2004, 2, 29, 12, 20, 30, 0, LONDON), result); // <-- TC fails here
}
src/test/java/org/joda/time/format/TestDateTimeFormatter.java:908-913
public void testParseInto_monthDay_withDefaultYear_feb29() {
DateTimeFormatter f = DateTimeFormat.forPattern("M d").withDefaultYear(2012);
MutableDateTime result = new MutableDateTime(2004, 1, 9, 12, 20, 30, 0, LONDON);
assertEquals(4, f.parseInto(result, "2 29", 0));
assertEquals(new MutableDateTime(2004, 2, 29, 12, 20, 30, 0, LONDON), result); // <-- TC fails here
}
The faulty code:
Line is covered but NOT in slice
Line is covered and in slice
Line is in slice but NOT covered
src/main/java/org/joda/time/format/DateTimeFormatter.java:708-724
public int parseInto(ReadWritableInstant instant, String text, int position) {
DateTimeParser parser = requireParser();
if (instant == null) {
throw new IllegalArgumentException("Instant must not be null");
}
long instantMillis = instant.getMillis();
Chronology chrono = instant.getChronology();
long instantLocal = instantMillis + chrono.getZone().getOffset(instantMillis);
chrono = selectChronology(chrono);
DateTimeParserBucket bucket = new DateTimeParserBucket( //<-- statement includes bug
instantLocal, chrono, iLocale, iPivotYear, iDefaultYear); //<-- BUG!!
int newPos = parser.parseInto(bucket, text, position);
instant.setMillis(bucket.computeMillis(false, text));
if (iOffsetParsed && bucket.getOffsetInteger() != null) {
int parsedOffset = bucket.getOffsetInteger();
DateTimeZone parsedZone = DateTimeZone.forOffsetMillis(parsedOffset);
chrono = chrono.withZone(parsedZone);
} else if (bucket.getZone() != null) {
chrono = chrono.withZone(bucket.getZone());
}
instant.setChronology(chrono);
if (iZone != null) {
instant.setZone(iZone);
}
return newPos;
}
Other code:
src/test/java/org/joda/time/format/TestDateTimeFormatter.java:866-871
public void testParseInto_monthOnly() {
DateTimeFormatter f = DateTimeFormat.forPattern("M").withLocale(Locale.UK);
MutableDateTime result = new MutableDateTime(2004, 1, 9, 12, 20, 30, 0, LONDON);
assertEquals(1, f.parseInto(result, "5", 0));
assertEquals(new MutableDateTime(2004, 5, 9, 12, 20, 30, 0, LONDON), result);
}
The faulty code for the above test:
src/main/java/org/joda/time/format/DateTimeFormatter.java:708-724
public int parseInto(ReadWritableInstant instant, String text, int position) {
DateTimeParser parser = requireParser();
if (instant == null) {
throw new IllegalArgumentException("Instant must not be null");
}
long instantMillis = instant.getMillis();
Chronology chrono = instant.getChronology();
long instantLocal = instantMillis + chrono.getZone().getOffset(instantMillis);
chrono = selectChronology(chrono);
DateTimeParserBucket bucket = new DateTimeParserBucket( //<-- statement includes bug
instantLocal, chrono, iLocale, iPivotYear, iDefaultYear); //<-- BUG!!
int newPos = parser.parseInto(bucket, text, position);
instant.setMillis(bucket.computeMillis(false, text));
if (iOffsetParsed && bucket.getOffsetInteger() != null) {
int parsedOffset = bucket.getOffsetInteger();
DateTimeZone parsedZone = DateTimeZone.forOffsetMillis(parsedOffset);
chrono = chrono.withZone(parsedZone);
} else if (bucket.getZone() != null) {
chrono = chrono.withZone(bucket.getZone());
}
instant.setChronology(chrono);
if (iZone != null) {
instant.setZone(iZone);
}
return newPos;
}