Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8359441

Custom JFR repository location causes JVM to not start/crash

XMLWordPrintable

    • jfr
    • x86_64
    • linux

      A DESCRIPTION OF THE PROBLEM :
      Setting a custom JFR repository location (e.g. '-XX:FlightRecorderOptions=repository=.') can cause the JVM to not start and crash with the following error, if the ServiceLoader mechanism is used for type 'java.time.zone.ZoneRulesProvider':

      [0.097s][error][jfr,startup] java.time.zone.ZoneRulesProvider: Provider org.example.TestZoneRulesProvider not found
      java.util.ServiceConfigurationError: java.time.zone.ZoneRulesProvider: Provider org.example.TestZoneRulesProvider not found
      Error occurred during initialization of VM
      Failure when starting JFR on_create_vm_2

      This is easily reproducible with a minimal ZoneRulesProvider implementation. We encountered this problem initially with the ical4j library, for which we also reported a bug: https://github.com/ical4j/ical4j/issues/808

      The following is enough to trigger the issue with that library:

      java -XX:FlightRecorderOptions=repository=. -classpath ical4j-4.1.1.jar

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      In an empty directory with the patch from below:
      - patch -p1 < example.patch
      - mvn compile exec:exec

      , run 'mvn exec:exec'

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Execution should print "Success"
      ACTUAL -
      JVM crashes with error:

      [0.053s][error][jfr,startup] java.time.zone.ZoneRulesProvider: Provider org.example.TestZoneRulesProvider not found
      java.util.ServiceConfigurationError: java.time.zone.ZoneRulesProvider: Provider org.example.TestZoneRulesProvider not found
      Error occurred during initialization of VM
      Failure when starting JFR on_create_vm_2


      ---------- BEGIN SOURCE ----------
      diff --git c/pom.xml i/pom.xml
      new file mode 100644
      index 0000000..8997c14
      --- /dev/null
      +++ i/pom.xml
      @@ -0,0 +1,36 @@
      +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
      + <modelVersion>4.0.0</modelVersion>
      + <groupId>org.example</groupId>
      + <artifactId>jfr-service-loader-crash</artifactId>
      + <version>1.0-SNAPSHOT</version>
      + <properties>
      + <maven.compiler.release>21</maven.compiler.release>
      + </properties>
      +
      + <build>
      + <plugins>
      + <plugin>
      + <groupId>org.codehaus.mojo</groupId>
      + <artifactId>exec-maven-plugin</artifactId>
      + <version>3.5.1</version>
      + <configuration>
      + <executable>java</executable>
      + <arguments>
      + <argument>-classpath</argument>
      + <classpath/>
      + <!--
      + specifying any custom repository location causes the VM to crash with error:
      + [error][jfr,startup] java.time.zone.ZoneRulesProvider: Provider org.example.TestZoneRulesProvider not found
      + java.util.ServiceConfigurationError: java.time.zone.ZoneRulesProvider: Provider org.example.TestZoneRulesProvider not found
      + Error occurred during initialization of VM
      + Failure when starting JFR on_create_vm_2
      + -->
      + <argument>-XX:FlightRecorderOptions=repository=.</argument>
      + <argument>org.example.TestZoneRulesProvider</argument>
      + </arguments>
      + </configuration>
      + </plugin>
      + </plugins>
      + </build>
      +</project>
      diff --git c/src/main/java/org/example/TestZoneRulesProvider.java i/src/main/java/org/example/TestZoneRulesProvider.java
      new file mode 100644
      index 0000000..ba5fa03
      --- /dev/null
      +++ i/src/main/java/org/example/TestZoneRulesProvider.java
      @@ -0,0 +1,28 @@
      +package org.example;
      +
      +import java.time.zone.ZoneRules;
      +import java.time.zone.ZoneRulesProvider;
      +import java.util.NavigableMap;
      +import java.util.Set;
      +
      +public class TestZoneRulesProvider extends ZoneRulesProvider {
      +
      + public static void main(String[] args) {
      + System.out.println("Success");
      + }
      +
      + @Override
      + protected Set<String> provideZoneIds() {
      + return Set.of();
      + }
      +
      + @Override
      + protected ZoneRules provideRules(String zoneId, boolean forCaching) {
      + return null;
      + }
      +
      + @Override
      + protected NavigableMap<String, ZoneRules> provideVersions(String zoneId) {
      + return null;
      + }
      +}
      diff --git c/src/main/resources/META-INF/services/java.time.zone.ZoneRulesProvider i/src/main/resources/META-INF/services/java.time.zone.ZoneRulesProvider
      new file mode 100644
      index 0000000..7a63606
      --- /dev/null
      +++ i/src/main/resources/META-INF/services/java.time.zone.ZoneRulesProvider
      @@ -0,0 +1 @@
      +org.example.TestZoneRulesProvider

      ---------- END SOURCE ----------

            jnordstrom Joakim Nordström
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: