Bug (Race-Condition) - Refactor use of System.(get|set|clear)Property
Created by: gndrm
Description
When using the openapi-generator-maven-plugin in a multi module Build with maven failsafe-plugin for Integration Tests, the generator is not working properly. Race conditions arise, since surefires AbstractSurefireMojo (Base class for IntegrationTestMojo) clones the Properties Object returned by System.getProperties() before the run and sets it as the new Properties in System afterwards.
Now consider the following sequence of statements:
- surefire clones System properties
- generator-maven-plugin sets Properties
- surefire resets System Properties (generators properties are gone)
- DefaultGenerator tries to read Properties
This breaks the plugin configuration and causes unintended behaviour.
openapi-generator version
3.3.0, but as far as i can see, the newest version doesn't change anything in regard to this behaviour.
Suggest a fix/enhancement
remove all references to System Properties, since those can be modified from everywhere and everybody inside the same JVM. Instead define a POJO-GeneratorProperties Object, which gets passed from GodeGenMojo to DefaultGenerator. Alternatively (what i have done so far) implement static class which initially clones the System Properties in a InheritableThreadLocal field and provides access to the cloned Object via (get|set|clear)Property Methods. This way you still have easy access to manipulate those properties, but you are not running the risk of losing Properties in a multi-threaded environment. This would also guarantee right behaviour, if you want to run two parallel executions of generator-plugin.