Skip to content

[Native Image] HijrahChronology is broken in native mode #11410

Open
@Eng-Fouad

Description

@Eng-Fouad

Describe the Issue

Issue 1:

Tried to use HijrahChronology in JDK 22, 23, and 24, and I got this exception:

java.time.DateTimeException: Unable to initialize HijrahCalendar: Hijrah-umalqura
	at java.base@24.0.1/java.time.chrono.HijrahChronology.loadCalendarData(HijrahChronology.java:915)
	at java.base@24.0.1/java.time.chrono.HijrahChronology.checkCalendarInit(HijrahChronology.java:328)
	at java.base@24.0.1/java.time.chrono.HijrahChronology.getHijrahDateInfo(HijrahChronology.java:581)
	at java.base@24.0.1/java.time.chrono.HijrahDate.<init>(HijrahDate.java:286)
	at java.base@24.0.1/java.time.chrono.HijrahDate.ofEpochDay(HijrahDate.java:168)
	at java.base@24.0.1/java.time.chrono.HijrahChronology.date(HijrahChronology.java:464)
        ...
Caused by: java.lang.RuntimeException: Hijrah calendar resource not found: hijrah-config-Hijrah-umalqura_islamic-umalqura.properties
	at java.base@24.0.1/java.time.chrono.HijrahChronology.readConfigProperties(HijrahChronology.java:825)
	at java.base@24.0.1/java.time.chrono.HijrahChronology.loadCalendarData(HijrahChronology.java:846)
	... 67 more

Isn't hijrah-config-Hijrah-umalqura_islamic-umalqura.properties supposed to be included by default by GraalVM?

"resources": [
    {
      "module": "java.base",
      "glob": "java/time/chrono/hijrah-config-Hijrah-umalqura_islamic-umalqura.properties"
    }
  ]

Issue 2:

Since JDK24+, I cannot use HijrahChronology on static block unless I initialize the containing class at runtime:

public class DateTimeUtils {
    // ...
    private static final DateTimeFormatter ARABIC_HIJRI_DATE_FORMATTER = DateTimeFormatter.ofPattern("dd\\MM\\yyyy G").localizedBy(LOCALE_AR).withChronology(HijrahChronology.INSTANCE);
    private static final DateTimeFormatter ENGLISH_HIJRI_DATE_FORMATTER = DateTimeFormatter.ofPattern("dd/MM/yyyy G").localizedBy(LOCALE_EN).withChronology(HijrahChronology.INSTANCE);
}

even if I include --initialize-at-run-time=io.fouad.backend.core.utils.DateTimeUtils, I got NPE:

HijrahChronology:

/**
     * Static initialization of the built-in calendars.
     * The data is not loaded until it is used.
     */
    static {
        INSTANCE = new HijrahChronology("Hijrah-umalqura", "islamic-umalqura");
        // Register it by its aliases
        AbstractChronology.registerChrono(INSTANCE, "Hijrah");
        AbstractChronology.registerChrono(INSTANCE, "islamic");

        // custom config chronologies
        CONF_PATH = Path.of(StaticProperty.javaHome(), "conf", "chronology");
        registerCustomChrono();
    }

StaticProperty.javaHome() causes the NPE, and the workaround is to add -Djava.home= when executing the native image.

Using the latest version of GraalVM can resolve many issues.

GraalVM Version

24

Operating System and Version

Ubuntu 24.04

Troubleshooting Confirmation

Run Command

.

Expected Behavior

.

Actual Behavior

.

Steps to Reproduce

.

Additional Context

No response

Run-Time Log Output and Error Messages

No response

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions