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

CompletableFuture can't find files from classpath

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      Docker Image: eclipse-temurin:17.0.8_7-jre-alpine

      A DESCRIPTION OF THE PROBLEM :
      I have the following code in my spring boot project:

      ```
      import java.util.List;
      import java.util.concurrent.CompletableFuture;

      import org.demo.controller.resources.HelmInfo;
      import org.demo.service.KubernetesService;
      import org.springframework.beans.factory.annotation.Autowired;
      import org.springframework.beans.factory.annotation.Qualifier;
      import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
      import org.springframework.web.bind.annotation.GetMapping;
      import org.springframework.web.bind.annotation.RequestMapping;
      import org.springframework.web.bind.annotation.RequestParam;
      import org.springframework.web.bind.annotation.RestController;

      @RestController
      @RequestMapping(KubernetesServiceController.ISTE_KUBERNETES_RESOURCE)
      public class KubernetesServiceController
      {
          public static final String ISTE_KUBERNETES_RESOURCE = "/kubernetes";

          public static final String HELM_CHART_LIST = "/helmChartList";

          @Autowired
          @Qualifier("rest-thread-pool")
          private ThreadPoolTaskScheduler threadPool;

          @Autowired
          private KubernetesService kubeService;

          @GetMapping(HELM_CHART_LIST)
          public CompletableFuture<List<HelmInfo>> helmChartList(@RequestParam(required = false) String taskName,
                          @RequestParam(required = false, defaultValue = "false") Boolean failed)
          {
              return CompletableFuture.supplyAsync(() -> kubeService.helmChartList(taskName, failed));
          }

      }
      ```

      With jre 17.0.3_7 this code runs well and delivers HelmList objects.

      But switching to jre 17.0.8_7 I get the following exception:
      ```
      java.io.FileNotFoundException: class path resource [scripts/helm_list_script.sh] cannot be opened because it does not exist
              at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:211) ~[spring-core-6.0.11.jar!/:6.0.11]
              at org.demo.command.CommandExecutor.executeFile(CommandExecutor.java:138) ~[classes!/:na]
              at org.demo.service.HelmService.executeHelmChartListScript(HelmService.java:73) ~[classes!/:na]
              at org.demo.service.KubernetesService.helmChartList(KubernetesService.java:88) ~[classes!/:na]
              at org.demo.controller.KubernetesServiceController.lambda$helmChartList$0(KubernetesServiceController.java:37) ~[classes!/:na]
              at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(Unknown Source) ~[na:na]
              at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.exec(Unknown Source) ~[na:na]
              at java.base/java.util.concurrent.ForkJoinTask.doExec(Unknown Source) ~[na:na]
              at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(Unknown Source) ~[na:na]
              at java.base/java.util.concurrent.ForkJoinPool.scan(Unknown Source) ~[na:na]
              at java.base/java.util.concurrent.ForkJoinPool.runWorker(Unknown Source) ~[na:na]
              at java.base/java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source) ~[na:na]
      ```

      Refactoring the code to:
      ```
          @GetMapping(HELM_CHART_LIST)
          public List<HelmInfo> helmChartList(@RequestParam(required = false) String taskName,
                          @RequestParam(required = false, defaultValue = "false") Boolean failed)
          {
              return kubeService.helmChartList(taskName, failed);
          }
      ```
      is succeeding. So the problem is somehow bound to CompletableFuture. The jar file still contains the requested files, but the classloader can't find them.

      REGRESSION : Last worked in version 17


      FREQUENCY : always


            tongwan Andrew Wang
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: