cherni78 commented on PR #5732:
URL: 
https://github.com/apache/incubator-kie-drools/pull/5732#issuecomment-1969173878

   After a few more analyses @reinhapa and I found the problem with Wildfly 
31.0.0.
   It seems to be a ClassLoader-Problem. It happens in the method 
[ImmutableRuleCompilationPhase.compileRulesLevel](https://github.com/kiegroup/drools/blob/c8c6b2d08f696a18418ae4d7f4f471bb080ef5f7/drools-compiler/src/main/java/org/drools/compiler/builder/impl/processors/ImmutableRuleCompilationPhase.java#L267)
   
   The ContextClassLoader used within the ForkJoinPoolTask is not the same as 
within the `compileRulesLevel` method.
   When passing the ClassLoader into the lambda everything works as expected.
   
   The following patch worked:
   ```
   diff --git 
a/drools-compiler/src/main/java/org/drools/compiler/builder/impl/processors/ImmutableRuleCompilationPhase.java
 
b/drools-compiler/src/main/java/org/drools/compiler/builder/impl/processors/ImmutableRuleCompilationPhase.java
   index ac94c80e78..9a8055b9ee 100644
   --- 
a/drools-compiler/src/main/java/org/drools/compiler/builder/impl/processors/ImmutableRuleCompilationPhase.java
   +++ 
b/drools-compiler/src/main/java/org/drools/compiler/builder/impl/processors/ImmutableRuleCompilationPhase.java
   @@ -269,18 +269,25 @@ public class ImmutableRuleCompilationPhase extends 
AbstractPackageCompilationPha
            if (parallelRulesBuild) {
                Map<String, RuleBuildContext> ruleCxts = new 
ConcurrentHashMap<>();
                try {
   +                final ClassLoader contextClassLoader = 
Thread.currentThread().getContextClassLoader();
                    
KnowledgeBuilderImpl.ForkJoinPoolHolder.COMPILER_POOL.submit(() ->
                            rules.stream().parallel()
                                    .filter(ruleDescr -> 
filterAccepts(ResourceChange.Type.RULE, ruleDescr.getNamespace(), 
ruleDescr.getName()))
                                    .forEach(ruleDescr -> {
   -                                    initRuleDescr(packageDescr, 
pkgRegistry, ruleDescr);
   -                                    RuleBuildContext context = 
buildRuleBuilderContext(pkgRegistry, ruleDescr);
   -                                    ruleCxts.put(ruleDescr.getName(), 
context);
   -                                    List<? extends KnowledgeBuilderResult> 
results = addRule(context);
   -                                    if (!results.isEmpty()) {
   -                                        synchronized (this.results) {
   -                                            this.results.addAll(results);
   -                                        }
   +                                    final ClassLoader 
savedCurrentClassLoader = Thread.currentThread().getContextClassLoader();
   +                                    try {
   +                                      
Thread.currentThread().setContextClassLoader(contextClassLoader);
   +                                      initRuleDescr(packageDescr, 
pkgRegistry, ruleDescr);
   +                                      RuleBuildContext context = 
buildRuleBuilderContext(pkgRegistry, ruleDescr);
   +                                      ruleCxts.put(ruleDescr.getName(), 
context);
   +                                      List<? extends 
KnowledgeBuilderResult> results = addRule(context);
   +                                      if (!results.isEmpty()) {
   +                                          synchronized (this.results) {
   +                                              this.results.addAll(results);
   +                                          }
   +                                      }
   +                                    } finally {
   +                                      
Thread.currentThread().setContextClassLoader(savedCurrentClassLoader);
                                        }
                                    })
                    ).get();
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to