Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -1856,6 +1856,14 @@ protected void computeTime() {

if (isSet(ERA)) {
era = internalGet(ERA);
// Don't check under, historically we have allowed values under
// BEFORE_MEIJI to be ignored during normalization
// We check against eras.length (not the highest constant ERA value)
// due to future added eras, or additional eras via
// "jdk.calendar.japanese.supplemental.era"
if (era >= eras.length) {
throw new IllegalArgumentException("Invalid era");
}
year = isSet(YEAR) ? internalGet(YEAR) : 1;
} else {
if (isSet(YEAR)) {
Expand Down
10 changes: 8 additions & 2 deletions test/jdk/java/util/Calendar/Builder/BuilderTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -23,8 +23,9 @@

/*
* @test
* @bug 4745761
* @bug 4745761 8350646
* @summary Unit test for Calendar.Builder.
* @run main BuilderTest
*/

import java.time.LocalDateTime;
Expand Down Expand Up @@ -245,6 +246,11 @@ private static void testExceptions() {
checkException(calb, IllegalArgumentException.class);
calb = builder().setCalendarType("japanese").setWeekDate(2013, 1, MONDAY);
checkException(calb, IllegalArgumentException.class);
// JDK-8350646 : Ensure IAE (instead of AIOOBE) for ERA over largest supported
calb = builder().setCalendarType("japanese").setFields(ERA, 6);
checkException(calb, IllegalArgumentException.class);
// Note that we don't check ERAs under BEFORE_MEIJI, i.e. -1, -2, ... as
// historically JapaneseImperialCalendar ignores such values when normalizing
}

private static Calendar.Builder builder() {
Expand Down
18 changes: 17 additions & 1 deletion test/jdk/java/util/Calendar/SupplementalJapaneseEraTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -67,6 +67,22 @@ public static void main(String[] args) {
}

private static void testProperty() {
// JDK-8350646: Ensure that IAE is thrown for out of range era, when
// additional era is defined
try {
new Calendar.Builder()
.setCalendarType("japanese")
.setFields(ERA, JapaneseEra.values().length + 2)
.build();
System.err.println("Out of range era should have thrown IAE");
errors++;
} catch (Exception e) {
if (!(e instanceof IllegalArgumentException)) {
System.err.printf("Out of range era threw \"%s\" instead of IAE\n", e);
errors++;
}
}

Calendar jcal = new Calendar.Builder()
.setCalendarType("japanese")
.setFields(ERA, 6, YEAR, 1, DAY_OF_YEAR, 1)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -23,7 +23,7 @@

/*
* @test
* @bug 8048123 8054214 8173423
* @bug 8048123 8054214 8173423 8350646
* @summary Test for jdk.calendar.japanese.supplemental.era support
* @library /test/lib
* @build SupplementalJapaneseEraTest
Expand Down