From d91c63020838bce9eca177ee610018d5b88fba2d Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 3 Sep 2020 15:48:00 +0200 Subject: [PATCH] [Minor] Catch trying to instantiate abstract policies --- .../java/li/strolch/policy/DefaultPolicyHandler.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/li.strolch.agent/src/main/java/li/strolch/policy/DefaultPolicyHandler.java b/li.strolch.agent/src/main/java/li/strolch/policy/DefaultPolicyHandler.java index 8769937c8..d6885ce2f 100644 --- a/li.strolch.agent/src/main/java/li/strolch/policy/DefaultPolicyHandler.java +++ b/li.strolch.agent/src/main/java/li/strolch/policy/DefaultPolicyHandler.java @@ -103,11 +103,13 @@ public class DefaultPolicyHandler extends StrolchComponent implements PolicyHand DBC.PRE.assertNotNull("tx must not be null!", tx); try { - Class clazz; if (defaultDef != null && !isPolicyDefAvailable(policyDef)) - clazz = defaultDef.accept(this); - else - clazz = policyDef.accept(this); + policyDef = defaultDef; + + Class clazz = policyDef.accept(this); + if (clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers())) + throw new IllegalArgumentException( + "Class " + clazz.getName() + " can not be instantiated as it is not a concrete class!"); @SuppressWarnings("unchecked") Constructor constructor = (Constructor) getConstructorForPolicy(clazz);