From 15da5c069fdaf9d270ec29b720be16ea6c949575 Mon Sep 17 00:00:00 2001 From: Jan-Willem Gmelig Meyling Date: Mon, 28 Dec 2020 13:46:38 +0100 Subject: [PATCH] [#2697] Use ECJ compiler on JRE's without compiler for Alias.* --- .../querydsl/collections/DefaultEvaluatorFactory.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/querydsl-collections/src/main/java/com/querydsl/collections/DefaultEvaluatorFactory.java b/querydsl-collections/src/main/java/com/querydsl/collections/DefaultEvaluatorFactory.java index 4c500866b..b4fd192fc 100644 --- a/querydsl-collections/src/main/java/com/querydsl/collections/DefaultEvaluatorFactory.java +++ b/querydsl-collections/src/main/java/com/querydsl/collections/DefaultEvaluatorFactory.java @@ -21,6 +21,7 @@ import java.util.Map; import javax.annotation.Nullable; import javax.tools.JavaCompiler; +import javax.tools.ToolProvider; import com.google.common.primitives.Primitives; import com.mysema.codegen.ECJEvaluatorFactory; @@ -52,7 +53,7 @@ public class DefaultEvaluatorFactory { public DefaultEvaluatorFactory(CollQueryTemplates templates) { this(templates, - Thread.currentThread().getContextClassLoader()); + Thread.currentThread().getContextClassLoader() != null ? Thread.currentThread().getContextClassLoader() : DefaultEvaluatorFactory.class.getClassLoader()); } public DefaultEvaluatorFactory(CollQueryTemplates templates, EvaluatorFactory factory) { @@ -68,10 +69,11 @@ public class DefaultEvaluatorFactory { protected DefaultEvaluatorFactory(CollQueryTemplates templates, ClassLoader classLoader) { this.templates = templates; - if (classLoader instanceof URLClassLoader) { - this.factory = new JDKEvaluatorFactory((URLClassLoader) classLoader); + final JavaCompiler systemJavaCompiler = ToolProvider.getSystemJavaCompiler(); + if (classLoader instanceof URLClassLoader && systemJavaCompiler != null) { + this.factory = new JDKEvaluatorFactory((URLClassLoader) classLoader, systemJavaCompiler); } else { - // for OSGi compatibility + // for OSGi and JRE compatibility this.factory = new ECJEvaluatorFactory(classLoader); } }