-
Bug
-
Resolution: Fixed
-
P4
-
13, 15
-
b09
-
Not verified
A DESCRIPTION OF THE PROBLEM :
WeekFields instances are meant to be singleton as this is also used to compare them. The isSupportedMethod in TemporalAccessor depends on this.
WeekFields.ISO is created with
public static final WeekFields ISO = new WeekFields(DayOfWeek.MONDAY, 4);
when it should possibly with:
public static final WeekFields ISO = WeekFields.of(DayOfWeek.MONDAY, 4);
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run a test with a custom CalendarDataProvider that returns start of the week Monday and minimal days of week = 4. -Djava.locale.providers=SPI
public class IsoCalendarDataProvider extends CalendarDataProvider {
@Override
public int getFirstDayOfWeek(Locale locale) {
return Calendar.MONDAY;
}
@Override
public int getMinimalDaysInFirstWeek(Locale locale) {
return 4;
}
@Override
public Locale[] getAvailableLocales() {
return new Locale[]{Locale.ROOT};
}
}
//testcase here
DateTimeFormatter formatter = new DateTimeFormatterBuilder()
.appendPattern("YYYY")
.toFormatter(Locale.ROOT);
TemporalAccessor parse = formatter.parse("2018");
assertTrue(parse.isSupported(WeekFields.ISO.weekBasedYear())); // never passes..
assertTrue(parse.isSupported(WeekFields.of(Locale.ROOT).weekBasedYear())); // always passes, we will run with SPI CalendarDataProvider, so the one below have to pass too
assertTrue(parse.isSupported(WeekFields.of(DayOfWeek.MONDAY,4).weekBasedYear())); // passes with SPI
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
assertTrue(parse.isSupported(WeekFields.ISO.weekBasedYear())); //passes
ACTUAL -
assertTrue(parse.isSupported(WeekFields.ISO.weekBasedYear())); // never passes..
---------- BEGIN SOURCE ----------
as in the description
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
assertTrue(parse.isSupported(WeekFields.of(DayOfWeek.MONDAY,4).weekBasedYear()));
works for me, but the WeekFields.ISO should too
FREQUENCY : always
WeekFields instances are meant to be singleton as this is also used to compare them. The isSupportedMethod in TemporalAccessor depends on this.
WeekFields.ISO is created with
public static final WeekFields ISO = new WeekFields(DayOfWeek.MONDAY, 4);
when it should possibly with:
public static final WeekFields ISO = WeekFields.of(DayOfWeek.MONDAY, 4);
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run a test with a custom CalendarDataProvider that returns start of the week Monday and minimal days of week = 4. -Djava.locale.providers=SPI
public class IsoCalendarDataProvider extends CalendarDataProvider {
@Override
public int getFirstDayOfWeek(Locale locale) {
return Calendar.MONDAY;
}
@Override
public int getMinimalDaysInFirstWeek(Locale locale) {
return 4;
}
@Override
public Locale[] getAvailableLocales() {
return new Locale[]{Locale.ROOT};
}
}
//testcase here
DateTimeFormatter formatter = new DateTimeFormatterBuilder()
.appendPattern("YYYY")
.toFormatter(Locale.ROOT);
TemporalAccessor parse = formatter.parse("2018");
assertTrue(parse.isSupported(WeekFields.ISO.weekBasedYear())); // never passes..
assertTrue(parse.isSupported(WeekFields.of(Locale.ROOT).weekBasedYear())); // always passes, we will run with SPI CalendarDataProvider, so the one below have to pass too
assertTrue(parse.isSupported(WeekFields.of(DayOfWeek.MONDAY,4).weekBasedYear())); // passes with SPI
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
assertTrue(parse.isSupported(WeekFields.ISO.weekBasedYear())); //passes
ACTUAL -
assertTrue(parse.isSupported(WeekFields.ISO.weekBasedYear())); // never passes..
---------- BEGIN SOURCE ----------
as in the description
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
assertTrue(parse.isSupported(WeekFields.of(DayOfWeek.MONDAY,4).weekBasedYear()));
works for me, but the WeekFields.ISO should too
FREQUENCY : always