You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by st...@apache.org on 2018/02/23 10:31:13 UTC
[2/3] deltaspike git commit: DELTASPIKE-1316 skip non-proxyable
classes from being annotated.
DELTASPIKE-1316 skip non-proxyable classes from being annotated.
Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/1f19c0e2
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/1f19c0e2
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/1f19c0e2
Branch: refs/heads/master
Commit: 1f19c0e210dc3d22c5429b09985b2d6deb9f3340
Parents: b5f9411
Author: Mark Struberg <st...@apache.org>
Authored: Fri Feb 23 11:24:00 2018 +0100
Committer: Mark Struberg <st...@apache.org>
Committed: Fri Feb 23 11:24:00 2018 +0100
----------------------------------------------------------------------
.../apache/deltaspike/core/util/ClassUtils.java | 71 ++++++++++++++++++++
.../interceptor/interdyn/InterDynExtension.java | 9 ++-
2 files changed, 79 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/1f19c0e2/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ClassUtils.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ClassUtils.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ClassUtils.java
index 897d69c..c2eac8f 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ClassUtils.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ClassUtils.java
@@ -18,8 +18,12 @@
*/
package org.apache.deltaspike.core.util;
+import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import javax.enterprise.inject.Typed;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.jar.Manifest;
@@ -104,6 +108,73 @@ public abstract class ClassUtils
return loader;
}
+
+ /**
+ * Checks whether the CDI rules for proxyable beans are met.
+ * See
+ * <a href="https://docs.jboss.org/cdi/spec/1.2/cdi-spec-with-assertions.html#unproxyable">
+ * CDI spec unproxyable bean types</a>
+ *
+ * @param type
+ * @return {@code true} if all proxy conditions are met, {@code false} otherwise
+ */
+ public static boolean isProxyableClass(Type type)
+ {
+ Class clazz = null;
+ if (type instanceof Class)
+ {
+ clazz = (Class) type;
+ }
+ if (type instanceof ParameterizedType && ((ParameterizedType) type).getRawType() instanceof Class)
+ {
+ clazz = (Class) ((ParameterizedType) type).getRawType();
+ }
+ if (clazz == null)
+ {
+ return false;
+ }
+
+ // classes which don’t have a non-private constructor with no parameters
+ try
+ {
+ Constructor constructor = clazz.getConstructor();
+ if (Modifier.isPrivate(constructor.getModifiers()))
+ {
+ return false;
+ }
+ }
+ catch (NoSuchMethodException e)
+ {
+ return false;
+ }
+
+ // classes which are declared final
+ if (Modifier.isFinal(clazz.getModifiers()))
+ {
+ return false;
+ }
+
+ // classes which have non-static, final methods with public, protected or default visibility,
+ for (Method method : clazz.getMethods())
+ {
+ if (!method.isBridge() && !method.isSynthetic() && !Modifier.isStatic(method.getModifiers()) &&
+ !Modifier.isPrivate(method.getModifiers()) && Modifier.isFinal(method.getModifiers()))
+ {
+ return false;
+ }
+ }
+
+
+ // primitive types,
+ // and array types.
+ if (clazz.isPrimitive() || clazz.isArray())
+ {
+ return false;
+
+ }
+ return true;
+ }
+
/**
* Tries to load a class based on the given name and interface or abstract class.
* @param name name of the concrete class
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/1f19c0e2/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/interceptor/interdyn/InterDynExtension.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/interceptor/interdyn/InterDynExtension.java b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/interceptor/interdyn/InterDynExtension.java
index bcbb4ff..72e54c1 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/interceptor/interdyn/InterDynExtension.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/interceptor/interdyn/InterDynExtension.java
@@ -115,13 +115,20 @@ public class InterDynExtension implements Deactivatable, Extension
{
if (enabled)
{
- String beanClassName = pat.getAnnotatedType().getJavaClass().getName();
AnnotatedType at = pat.getAnnotatedType();
+ String beanClassName = at.getJavaClass().getName();
AnnotatedTypeBuilder atb = null;
for (AnnotationRule rule : interceptorRules)
{
if (beanClassName.matches(rule.getRule()))
{
+ if (!ClassUtils.isProxyableClass(at.getJavaClass()))
+ {
+ logger.info("Skipping unproxyable class " + beanClassName +
+ " even if matches rule=" + rule.getRule());
+ return;
+ }
+
if (atb == null)
{
atb = new AnnotatedTypeBuilder();