Author: rmannibucau
Date: Fri Jun 16 11:23:14 2017
New Revision: 1798910
URL: http://svn.apache.org/viewvc?rev=1798910&view=rev
Log:
some more interception factory failure handling
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InterceptionFactoryImpl.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java
openwebbeans/trunk/webbeans-tck/testng-dev.xml
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InterceptionFactoryImpl.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InterceptionFactoryImpl.java?rev=1798910&r1=1798909&r2=1798910&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InterceptionFactoryImpl.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InterceptionFactoryImpl.java
Fri Jun 16 11:23:14 2017
@@ -43,6 +43,7 @@ public class InterceptionFactoryImpl<T>
private final Set<Annotation> qualifiers;
private final WebBeansContext context;
private boolean ignoreFinals;
+ private volatile boolean called;
public InterceptionFactoryImpl(final WebBeansContext context, final
AnnotatedType<T> at,
final Set<Annotation> qualifiers, final
CreationalContextImpl<T> cc)
@@ -69,6 +70,8 @@ public class InterceptionFactoryImpl<T>
@Override
public T createInterceptedInstance(final T originalInstance)
{
+ check();
+
ClassLoader classLoader = originalInstance.getClass().getClassLoader();
if (classLoader == null)
{
@@ -79,7 +82,7 @@ public class InterceptionFactoryImpl<T>
final AnnotatedTypeImpl<T> newAnnotatedType =
configurator.getNewAnnotatedType();
final InterceptorResolutionService.BeanInterceptorInfo interceptorInfo
=
context.getInterceptorResolutionService()
-
.calculateInterceptorInfo(newAnnotatedType.getTypeClosure(), qualifiers,
newAnnotatedType, ignoreFinals);
+
.calculateInterceptorInfo(newAnnotatedType.getTypeClosure(), qualifiers,
newAnnotatedType, !ignoreFinals);
final Class<T> subClass = factory.getCachedProxyClass(interceptorInfo,
newAnnotatedType, classLoader);
final Map<Interceptor<?>,Object> interceptorInstances =
context.getInterceptorResolutionService()
@@ -95,4 +98,24 @@ public class InterceptionFactoryImpl<T>
originalInstance, creationalContext, creationalContext,
interceptorInfo, subClass,
methodInterceptors, passivationId, interceptorInstances, c ->
false, (a, d) -> d);
}
+
+ private void check()
+ {
+ boolean ok = false;
+ if (!called)
+ {
+ synchronized (this)
+ {
+ if (!called)
+ {
+ called = true;
+ ok = true;
+ }
+ }
+ }
+ if (!ok)
+ {
+ throw new IllegalStateException("createInterceptedInstance() can
be called only once");
+ }
+ }
}
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java?rev=1798910&r1=1798909&r2=1798910&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorResolutionService.java
Fri Jun 16 11:23:14 2017
@@ -38,6 +38,7 @@ import org.apache.webbeans.util.ClassUti
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.UnproxyableResolutionException;
import javax.enterprise.inject.spi.Annotated;
import javax.enterprise.inject.spi.AnnotatedCallable;
import javax.enterprise.inject.spi.AnnotatedConstructor;
@@ -93,7 +94,7 @@ public class InterceptorResolutionServic
public <T> BeanInterceptorInfo calculateInterceptorInfo(Set<Type>
beanTypes, Set<Annotation> qualifiers, AnnotatedType<T> annotatedType,
- boolean
allowFinalMethod)
+ boolean
failOnFinal)
{
Asserts.assertNotNull(beanTypes, "beanTypes");
Asserts.assertNotNull(qualifiers, "qualifiers");
@@ -150,12 +151,12 @@ public class InterceptorResolutionServic
{
BusinessMethodInterceptorInfo methodInterceptorInfo = new
BusinessMethodInterceptorInfo();
- calculateEjbMethodInterceptors(methodInterceptorInfo,
allUsedEjbInterceptors, classLevelEjbInterceptors, annotatedMethod,
allowFinalMethod);
+ calculateEjbMethodInterceptors(methodInterceptorInfo,
allUsedEjbInterceptors, classLevelEjbInterceptors, annotatedMethod,
failOnFinal);
calculateCdiMethodInterceptors(methodInterceptorInfo,
InterceptionType.AROUND_INVOKE, allUsedCdiInterceptors, annotatedMethod,
- classInterceptorBindings,
classLevelInterceptors, allowFinalMethod);
+ classInterceptorBindings,
classLevelInterceptors, failOnFinal);
- calculateCdiMethodDecorators(methodInterceptorInfo, decorators,
annotatedMethod, allowFinalMethod);
+ calculateCdiMethodDecorators(methodInterceptorInfo, decorators,
annotatedMethod, failOnFinal);
if (methodInterceptorInfo.isEmpty() && (selfInterceptorBean ==
null || !selfInterceptorBean.isAroundInvoke()))
{
@@ -168,7 +169,7 @@ public class InterceptorResolutionServic
for (AnnotatedConstructor annotatedConstructor :
annotatedType.getConstructors())
{
final BusinessMethodInterceptorInfo constructorInterceptorInfo =
new BusinessMethodInterceptorInfo();
- calculateEjbMethodInterceptors(constructorInterceptorInfo,
allUsedEjbInterceptors, classLevelEjbInterceptors, annotatedConstructor,
allowFinalMethod);
+ calculateEjbMethodInterceptors(constructorInterceptorInfo,
allUsedEjbInterceptors, classLevelEjbInterceptors, annotatedConstructor,
failOnFinal);
if (constructorInterceptorInfo.isEmpty() && (selfInterceptorBean
== null || !selfInterceptorBean.isAroundInvoke()))
{
continue;
@@ -189,7 +190,7 @@ public class InterceptorResolutionServic
allUsedEjbInterceptors,
classLevelEjbInterceptors,
classInterceptorBindings,
- allowFinalMethod);
+ failOnFinal);
addLifecycleMethods(
lifecycleMethodInterceptorInfos,
@@ -200,7 +201,7 @@ public class InterceptorResolutionServic
allUsedEjbInterceptors,
classLevelEjbInterceptors,
classInterceptorBindings,
- allowFinalMethod);
+ failOnFinal);
List<Interceptor<?>> cdiInterceptors = new
ArrayList<Interceptor<?>>(allUsedCdiInterceptors);
Collections.sort(cdiInterceptors, new
InterceptorComparator(webBeansContext));
@@ -224,7 +225,7 @@ public class InterceptorResolutionServic
boolean proxyable = false;
for (AnnotatedConstructor<T> constructor :
annotatedType.getConstructors())
{
- if ((constructor.getParameters().isEmpty() &&
!isUnproxyable(constructor, allowFinalMethod)) ||
+ if ((constructor.getParameters().isEmpty() &&
!isUnproxyable(constructor, failOnFinal)) ||
constructor.isAnnotationPresent(Inject.class))
{
proxyable = true;
@@ -353,7 +354,7 @@ public class InterceptorResolutionServic
Set<Interceptor<?>>
allUsedEjbInterceptors,
List<Interceptor<?>>
classLevelEjbInterceptors,
Set<Annotation> classInterceptorBindings,
- boolean allowFinal)
+ boolean failOnFinal)
{
List<AnnotatedMethod<?>> foundMethods = new
ArrayList<AnnotatedMethod<?>>();
BusinessMethodInterceptorInfo methodInterceptorInfo = new
BusinessMethodInterceptorInfo();
@@ -367,17 +368,17 @@ public class InterceptorResolutionServic
if (lifecycleMethod.getParameters().size() == 0)
{
foundMethods.add(lifecycleMethod);
- calculateEjbMethodInterceptors(methodInterceptorInfo,
allUsedEjbInterceptors, classLevelEjbInterceptors, lifecycleMethod, allowFinal);
+ calculateEjbMethodInterceptors(methodInterceptorInfo,
allUsedEjbInterceptors, classLevelEjbInterceptors, lifecycleMethod,
failOnFinal);
- calculateCdiMethodInterceptors(methodInterceptorInfo,
interceptionType, allUsedCdiInterceptors, lifecycleMethod,
classInterceptorBindings, null, allowFinal);
+ calculateCdiMethodInterceptors(methodInterceptorInfo,
interceptionType, allUsedCdiInterceptors, lifecycleMethod,
classInterceptorBindings, null, failOnFinal);
}
}
for (AnnotatedConstructor<?> lifecycleMethod :
annotatedType.getConstructors())
{
// TODO: verifyLifecycleMethod(lifeycleAnnotation,
lifecycleMethod);
- calculateEjbMethodInterceptors(methodInterceptorInfo,
allUsedEjbInterceptors, classLevelEjbInterceptors, lifecycleMethod, allowFinal);
+ calculateEjbMethodInterceptors(methodInterceptorInfo,
allUsedEjbInterceptors, classLevelEjbInterceptors, lifecycleMethod,
failOnFinal);
- calculateCdiMethodInterceptors(methodInterceptorInfo,
interceptionType, allUsedCdiInterceptors, lifecycleMethod,
classInterceptorBindings, null, allowFinal);
+ calculateCdiMethodInterceptors(methodInterceptorInfo,
interceptionType, allUsedCdiInterceptors, lifecycleMethod,
classInterceptorBindings, null, failOnFinal);
}
if (foundMethods.size() > 0 )
@@ -416,9 +417,9 @@ public class InterceptorResolutionServic
private void calculateEjbMethodInterceptors(BusinessMethodInterceptorInfo
methodInterceptorInfo, Set<Interceptor<?>> allUsedEjbInterceptors,
List<Interceptor<?>>
classLevelEjbInterceptors, AnnotatedCallable annotatedMethod,
- boolean allowFinal)
+ boolean failOnFinal)
{
- boolean unproxyable = isUnproxyable(annotatedMethod, allowFinal);
+ boolean unproxyable = isUnproxyable(annotatedMethod, failOnFinal);
List<Interceptor<?>> methodInterceptors = new
ArrayList<Interceptor<?>>();
@@ -443,15 +444,20 @@ public class InterceptorResolutionServic
}
}
- private boolean isUnproxyable(AnnotatedCallable annotatedMethod, boolean
allowFinal)
+ private boolean isUnproxyable(final AnnotatedCallable annotatedMethod,
final boolean failOnFinal)
{
int modifiers = annotatedMethod.getJavaMember().getModifiers();
- return (!allowFinal && Modifier.isFinal(modifiers)) ||
Modifier.isPrivate(modifiers);
+ final boolean isFinal = Modifier.isFinal(modifiers);
+ if (failOnFinal && isFinal)
+ {
+ throw new UnproxyableResolutionException(annotatedMethod + " is
not proxyable");
+ }
+ return isFinal || Modifier.isPrivate(modifiers);
}
private void calculateCdiMethodDecorators(BusinessMethodInterceptorInfo
methodInterceptorInfo, List<Decorator<?>> decorators, AnnotatedMethod
annotatedMethod,
- boolean allowFinal)
+ boolean failOnFinal)
{
if (decorators == null || decorators.isEmpty())
{
@@ -470,7 +476,7 @@ public class InterceptorResolutionServic
Method decoratingMethod = getDecoratingMethod(decorator,
annotatedMethod);
if (decoratingMethod != null)
{
- if (isUnproxyable(annotatedMethod, allowFinal))
+ if (isUnproxyable(annotatedMethod, failOnFinal))
{
throw new WebBeansDeploymentException(annotatedMethod + "
is not proxyable, but an Decorator got defined on it!");
}
@@ -592,11 +598,11 @@ public class InterceptorResolutionServic
AnnotatedCallable
annotatedMethod,
Set<Annotation>
classInterceptorBindings,
List<Interceptor<?>>
classLevelInterceptors,
- boolean allowFinal)
+ boolean failOnFinal)
{
AnnotationManager annotationManager =
webBeansContext.getAnnotationManager();
- boolean unproxyable = isUnproxyable(annotatedMethod, allowFinal);
+ boolean unproxyable = isUnproxyable(annotatedMethod, failOnFinal);
boolean hasMethodInterceptors = false;
Map<Class<? extends Annotation>, Annotation>
cummulatedInterceptorBindings = new HashMap<Class<? extends Annotation>,
Annotation>();
Modified: openwebbeans/trunk/webbeans-tck/testng-dev.xml
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-tck/testng-dev.xml?rev=1798910&r1=1798909&r2=1798910&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-tck/testng-dev.xml (original)
+++ openwebbeans/trunk/webbeans-tck/testng-dev.xml Fri Jun 16 11:23:14 2017
@@ -18,7 +18,7 @@
<suite name="JSR-346-TCK" verbose="2" configfailurepolicy="continue">
<test name="JSR-346 TCK">
<classes>
- <class
name="org.jboss.cdi.tck.tests.extensions.interceptionFactory.broken.InvalidInterceptionFactoryInjectionPointTest"
/>
+ <class
name="org.jboss.cdi.tck.tests.extensions.interceptionFactory.broken.BrokenInterceptedInstanceTest"
/>
<!--
<class
name="org.jboss.cdi.tck.tests.event.parameterized.ParameterizedEventTest" />
<class name="org.jboss.cdi.tck.tests.event.fires.FireEventTest" />