public UnproxyableResolutionException validateProxyable()

in webbeans-impl/src/main/java/org/apache/webbeans/config/DeploymentValidationService.java [68:147]


    public UnproxyableResolutionException validateProxyable(OwbBean<?> bean, boolean ignoreFinalMethods)
    {
        if (allowProxyingClasses == null)
        {
            allowProxyingClasses = webBeansContext.getOpenWebBeansConfiguration().getConfigListValues(OpenWebBeansConfiguration.ALLOW_PROXYING_PARAM);
        }

        // Unproxyable test for NormalScoped beans
        if (webBeansContext.getBeanManagerImpl().isNormalScope(bean.getScope()))
        {
            ViolationMessageBuilder violationMessage = ViolationMessageBuilder.newViolation();

            Class<?> beanClass = bean.getReturnType();


            if(!beanClass.isInterface() && beanClass != Object.class)
            {
                if(beanClass.isPrimitive())
                {
                    violationMessage.addLine("It isn't possible to proxy a primitive type (" + beanClass.getName(), ")");
                }

                if(beanClass.isArray())
                {
                    violationMessage.addLine("It isn't possible to proxy an array type (", beanClass.getName(), ")");
                }

                if(!violationMessage.containsViolation())
                {
                    if (Modifier.isFinal(beanClass.getModifiers()))
                    {
                        violationMessage.addLine(beanClass.getName(), " is a final class! CDI doesn't allow to proxy that.");
                    }

                    if (!ignoreFinalMethods)
                    {
                        String finalMethodName = hasNonPrivateFinalMethod(beanClass);
                        if (finalMethodName != null)
                        {
                            if (allowProxyingClasses.contains(beanClass.getName()))
                            {
                                WebBeansLoggerFacade.getLogger(DeploymentValidationService.class)
                                        .info(beanClass.getName() + " has final method " +
                                                finalMethodName + ". CDI doesn't allow to proxy that." +
                                                " Continuing because the class is explicitly configured " +
                                                "to be treated as proxyable." +
                                                " Final methods shall not get invoked on this proxy!");
                            }
                            else
                            {
                                violationMessage.addLine(beanClass.getName(), " has final method " + finalMethodName + " CDI doesn't allow to proxy that.");
                            }
                        }
                    }

                    Constructor<?> cons = webBeansContext.getWebBeansUtil().getNoArgConstructor(beanClass);
                    if (cons == null)
                    {
                        violationMessage.addLine(beanClass.getName(), " has no explicit no-arg constructor!",
                                "A public or protected constructor without args is required!");
                    }
                    else if (Modifier.isPrivate(cons.getModifiers()))
                    {
                        boolean containsViolation = violationMessage.containsViolation();
                        violationMessage.addLine(beanClass.getName(), " has a >private< no-arg constructor! CDI doesn't allow to proxy that.");
                        if (!containsViolation)
                        { // lazy
                            return createUnproxyableResolutionException(violationMessage);
                        }
                    }
                }

                if(violationMessage.containsViolation())
                {
                    return createUnproxyableResolutionException(violationMessage);
                }
            }
        }
        return null;
    }