Details
-
Type:
Bug
-
Status: Resolved
-
Priority:
P3
-
Resolution: Fixed
-
Affects Version/s: 9
-
Fix Version/s: 9-repo-jigsaw
-
Component/s: core-libs
-
Labels:
-
Subcomponent:
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
}
}
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
}
}