use of org.jboss.weld.exceptions.UnproxyableResolutionException in project core by weld.
the class InterceptionFactoryImpl method createInterceptedInstance.
@Override
public T createInterceptedInstance(T instance) {
if (used) {
throw InterceptorLogger.LOG.interceptionFactoryNotReusable();
}
if (instance instanceof ProxyObject) {
InterceptorLogger.LOG.interceptionFactoryInternalContainerConstruct(instance.getClass());
return instance;
}
UnproxyableResolutionException exception = Proxies.getUnproxyableTypeException(annotatedType.getBaseType(), null, beanManager.getServices(), ignoreFinalMethods);
if (exception != null) {
throw exception;
}
used = true;
if (annotatedType.getJavaClass().isInterface()) {
throw InterceptorLogger.LOG.interceptionFactoryNotOnInstance(annotatedType.getJavaClass().getCanonicalName());
}
Optional<InterceptionFactoryData<T>> cached = beanManager.getServices().get(InterceptionFactoryDataCache.class).getInterceptionFactoryData(configurator != null ? configurator.complete() : annotatedType);
if (!cached.isPresent()) {
InterceptorLogger.LOG.interceptionFactoryNotRequired(annotatedType.getJavaClass().getSimpleName());
return instance;
}
InterceptionFactoryData<T> data = cached.get();
InterceptedProxyMethodHandler methodHandler = new InterceptedProxyMethodHandler(instance);
methodHandler.setInterceptorMethodHandler(new InterceptorMethodHandler(InterceptionContext.forNonConstructorInterception(data.getInterceptionModel(), creationalContext, beanManager, data.getSlimAnnotatedType())));
T proxy = (System.getSecurityManager() == null) ? data.getInterceptedProxyFactory().run() : AccessController.doPrivileged(data.getInterceptedProxyFactory());
((ProxyObject) proxy).setHandler(methodHandler);
return proxy;
}
use of org.jboss.weld.exceptions.UnproxyableResolutionException in project core by weld.
the class Proxies method getUnproxyableClassException.
private static UnproxyableResolutionException getUnproxyableClassException(Class<?> clazz, Bean<?> declaringBean, ServiceRegistry services, boolean ignoreFinalMethods) {
if (clazz.isInterface()) {
return null;
}
Constructor<?> constructor = null;
try {
constructor = SecurityActions.getDeclaredConstructor(clazz);
} catch (Exception ignored) {
}
if (clazz.isPrimitive()) {
return ValidatorLogger.LOG.notProxyablePrimitive(clazz, getDeclaringBeanInfo(declaringBean));
} else if (Reflections.isArrayType(clazz)) {
return ValidatorLogger.LOG.notProxyableArrayType(clazz, getDeclaringBeanInfo(declaringBean));
} else if (Reflections.isFinal(clazz)) {
return ValidatorLogger.LOG.notProxyableFinalType(clazz, getDeclaringBeanInfo(declaringBean));
} else {
Method finalMethod = Reflections.getNonPrivateNonStaticFinalMethod(clazz);
if (finalMethod != null) {
if (ignoreFinalMethods || Beans.shouldIgnoreFinalMethods(declaringBean) || services.get(WeldConfiguration.class).isFinalMethodIgnored(clazz.getName())) {
ValidatorLogger.LOG.notProxyableFinalMethodIgnored(finalMethod, getDeclaringBeanInfo(declaringBean));
} else {
return ValidatorLogger.LOG.notProxyableFinalMethod(clazz, finalMethod, getDeclaringBeanInfo(declaringBean));
}
}
}
UnproxyableResolutionException exception = services.get(ProxyInstantiator.class).validateNoargConstructor(constructor, clazz, declaringBean);
if (exception != null) {
return exception;
}
return null;
}
Aggregations