Skip to content

Commit 2f93d04

Browse files
committed
[GR-36046] Remove legacy CalendarSubstitutions from Native Image
PullRequest: graal/22099
2 parents 6577748 + 7807c98 commit 2f93d04

File tree

4 files changed

+60
-11
lines changed

4 files changed

+60
-11
lines changed

substratevm/src/com.oracle.svm.configure/src/com/oracle/svm/configure/trace/AccessAdvisor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ public final class AccessAdvisor {
127127
internalCallerFilter.addOrGetChildren("sun.util.**", ConfigurationFilter.Inclusion.Exclude);
128128
// Bundles calls Bundles.of
129129
internalCallerFilter.addOrGetChildren("sun.util.resources.Bundles", ConfigurationFilter.Inclusion.Include);
130+
// Class.forName calls in CalendarSystem.forName
131+
internalCallerFilter.addOrGetChildren("sun.util.calendar.CalendarSystem", ConfigurationFilter.Inclusion.Include);
130132

131133
excludeInaccessiblePackages(internalCallerFilter);
132134

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) 2025, 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.oracle.svm.core.jdk;
26+
27+
import java.util.GregorianCalendar;
28+
29+
import org.graalvm.nativeimage.hosted.RuntimeReflection;
30+
31+
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
32+
import com.oracle.svm.core.feature.InternalFeature;
33+
34+
import sun.util.calendar.JulianCalendar;
35+
36+
@AutomaticallyRegisteredFeature
37+
public class CalendarFeature implements InternalFeature {
38+
@Override
39+
public void beforeAnalysis(BeforeAnalysisAccess access) {
40+
// GregorianCalendar might use JulianCalendar via reflection
41+
access.registerReachabilityHandler(a -> {
42+
RuntimeReflection.register(JulianCalendar.class);
43+
RuntimeReflection.registerForReflectiveInstantiation(JulianCalendar.class);
44+
}, GregorianCalendar.class);
45+
}
46+
}

web-image/mx.web-image/suite.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
"java.base": [
101101
"sun.nio.ch",
102102
"sun.security.provider",
103+
"sun.util.calendar",
103104
"jdk.internal.misc",
104105
"jdk.internal.util",
105106
],

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/CalendarSubstitutions.java renamed to web-image/src/com.oracle.svm.webimage/src/com/oracle/svm/webimage/substitute/WebImageCalendarSubstitutions.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -22,7 +22,8 @@
2222
* or visit www.oracle.com if you need additional information or have any
2323
* questions.
2424
*/
25-
package com.oracle.svm.core.jdk;
25+
26+
package com.oracle.svm.webimage.substitute;
2627

2728
import java.util.Calendar;
2829
import java.util.GregorianCalendar;
@@ -43,39 +44,38 @@
4344
*/
4445

4546
@TargetClass(java.util.Calendar.class)
46-
final class Target_java_util_Calendar {
47+
final class Target_java_util_Calendar_Web {
4748

4849
@Substitute
4950
private static Calendar createCalendar(TimeZone zone, Locale aLocale) {
5051
return new GregorianCalendar(zone, aLocale);
5152
}
5253
}
5354

54-
@TargetClass(sun.util.calendar.CalendarSystem.class)
55-
final class Target_sun_util_calendar_CalendarSystem {
55+
@TargetClass(CalendarSystem.class)
56+
final class Target_sun_util_calendar_CalendarSystem_Web {
5657

5758
@Substitute
5859
private static CalendarSystem forName(String calendarName) {
5960
if ("gregorian".equals(calendarName)) {
60-
return Util_sun_util_calendar_CalendarSystem.GREGORIAN;
61+
return Util_sun_util_calendar_CalendarSystem_Web.GREGORIAN;
6162
} else if ("japanese".equals(calendarName)) {
62-
return Util_sun_util_calendar_CalendarSystem.JAPANESE;
63+
return Util_sun_util_calendar_CalendarSystem_Web.JAPANESE;
6364
} else if ("julian".equals(calendarName)) {
64-
return Util_sun_util_calendar_CalendarSystem.JULIAN;
65+
return Util_sun_util_calendar_CalendarSystem_Web.JULIAN;
6566
} else {
6667
throw VMError.unsupportedFeature("CalendarSystem.forName " + calendarName);
6768
}
6869
}
6970
}
7071

71-
final class Util_sun_util_calendar_CalendarSystem {
72-
72+
final class Util_sun_util_calendar_CalendarSystem_Web {
7373
// The static fields are initialized during native image generation.
7474
static final CalendarSystem GREGORIAN = CalendarSystem.forName("gregorian");
7575
static final CalendarSystem JAPANESE = CalendarSystem.forName("japanese");
7676
static final CalendarSystem JULIAN = CalendarSystem.forName("julian");
7777
}
7878

7979
/** Dummy class to have a class with the file's name. */
80-
public final class CalendarSubstitutions {
80+
public final class WebImageCalendarSubstitutions {
8181
}

0 commit comments

Comments
 (0)