1. copy ps-single-thread-1.0.0-SNAPSHOT.jar to lib\platform\ext
2. start xap with: gs-agent.bat --manager-local --gsc=1
3. deploy and undeploy a-test-pu-3.0.0-SNAPSHOT.jar three times and check in the logs for REPRODUCED.
ps-single-thread-1.0.0-SNAPSHOT.jar "simulates" the scheduler of CompletableFuture" or any other thread which is unique within a process (e.g. ForkJoinPool)
Added more logs to SpaceAggregateService that show the cause of the problem.
The problem is that context class loaders are inherited from the parent thread. During the first deployment the thread SingletonThread gets the context class loader from the spring thread. Which is in this case the correct ServiceClassLoader.
During the second deployment you will notice that the SingletonThread and the newly created thread are using the old and not the new ServiceClassLoader. But for not completely understood reason it does work for the second deployment.
On the third deployment it always fails.
We suspect that ReflectionUtil#getClassTargetLoader may return the wrong class loader on the third try.