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

spec clarification for ServiceLoader#stream for stream operations after clearing cache

    Details

      Description

      The spec (comments) for the stream method does not mention that it throws java.util.ConcurrentModificationException when existing streams of the serviceloader are used after clearing the cache by calling ServiceLoader#reload method.

      Simple test case to check :

      Provider:
      testmodules/p/module/provider/ModuleTest.java
      testmodules/p/module-info.java

      module p{
      requires s;
      provides module.test.ModuleTestService with module.provider.ModuleTest;
      }

      Service:
      testmodules/s/module/test/ModuleTestService.java
      testmodules/s/module/test/Test.java
      testmodules/s/module-info.java

      module s{
      exports module.test;
      uses module.test.ModuleTestService;
      }

      public class Test{
      public static void main(String[] args){
      new Test().run();
      }

      public void run(){
            ServiceLoader<ModuleTestService> serviceLoader= ServiceLoader.load(ModuleTestService.class);
            Stream<ServiceLoader.Provider<ModuleTestService>> stream = serviceLoader.stream();
            serviceLoader.reload(); //clears cache
            stream.findFirst(); // throws ConcurrentModificationException, worth mentioning in spec as it is mentioned for iterator method's spec
        }
      }

        Attachments

          Activity

            People

            • Assignee:
              alanb Alan Bateman
              Reporter:
              bnallakaluva Bharath Nallakaluva (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: