diff --git a/querydsl-core/src/main/java/com/querydsl/core/types/ConstructorExpression.java b/querydsl-core/src/main/java/com/querydsl/core/types/ConstructorExpression.java index af9d6aa3c..2f27fb9a5 100644 --- a/querydsl-core/src/main/java/com/querydsl/core/types/ConstructorExpression.java +++ b/querydsl-core/src/main/java/com/querydsl/core/types/ConstructorExpression.java @@ -20,7 +20,6 @@ import java.lang.reflect.InvocationTargetException; import java.util.Arrays; import java.util.List; -import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; import com.google.common.base.Function; @@ -62,10 +61,9 @@ public class ConstructorExpression extends FactoryExpressionBase { private final Class[] parameterTypes; - @Nullable - private transient Constructor constructor; + private final transient Constructor constructor; - private transient Iterable> transformers; + private final transient Iterable> transformers; protected ConstructorExpression(Class type, Expression... args) { this(type, getParameterTypes(args), ImmutableList.copyOf(args)); @@ -77,8 +75,14 @@ public class ConstructorExpression extends FactoryExpressionBase { protected ConstructorExpression(Class type, Class[] paramTypes, ImmutableList> args) { super(type); - this.parameterTypes = getConstructorParameters(type, paramTypes).clone(); - this.args = args; + try { + this.parameterTypes = getConstructorParameters(type, paramTypes).clone(); + this.args = args; + this.constructor = getConstructor(getType(), parameterTypes); + this.transformers = getTransformers(constructor); + } catch (NoSuchMethodException e) { + throw new IllegalArgumentException(e); + } } /** @@ -128,18 +132,12 @@ public class ConstructorExpression extends FactoryExpressionBase { @SuppressWarnings("unchecked") public T newInstance(Object... args) { try { - if (constructor == null) { - constructor = getConstructor(getType(), parameterTypes); - transformers = getTransformers(constructor); - } for (Function transformer : transformers) { args = transformer.apply(args); } return (T) constructor.newInstance(args); } catch (SecurityException e) { throw new ExpressionException(e.getMessage(), e); - } catch (NoSuchMethodException e) { - throw new ExpressionException(e.getMessage(), e); } catch (InstantiationException e) { throw new ExpressionException(e.getMessage(), e); } catch (IllegalAccessException e) {