Skip to content

Commit

Permalink
WELD-1583 - Confusing error message when an interceptor/decorator has…
Browse files Browse the repository at this point in the history
… a non-passivating dependency
  • Loading branch information
bafco authored and jharting committed Jan 14, 2014
1 parent 97f8ecc commit 2d6a259
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
28 changes: 22 additions & 6 deletions impl/src/main/java/org/jboss/weld/bootstrap/Validator.java
Expand Up @@ -224,7 +224,7 @@ private void validateInterceptors(BeanManagerImpl beanManager, AbstractClassBean
}
for (InjectionPoint injectionPoint : interceptor.getInjectionPoints()) {
Bean<?> resolvedBean = beanManager.resolve(beanManager.getBeans(injectionPoint));
validateInjectionPointPassivationCapable(injectionPoint, resolvedBean, beanManager);
validateInterceptorDecoratorInjectionPointPassivationCapable(injectionPoint, resolvedBean, beanManager, classBean);
}
}
if (interceptorMetadata.getInterceptorFactory() instanceof ClassMetadataInterceptorFactory<?>) {
Expand All @@ -242,7 +242,7 @@ private void validateInterceptors(BeanManagerImpl beanManager, AbstractClassBean
validateInjectionPoint(injectionPoint, beanManager);
if (passivationCapabilityCheckRequired) {
Bean<?> resolvedBean = beanManager.resolve(beanManager.getBeans(injectionPoint));
validateInjectionPointPassivationCapable(injectionPoint, resolvedBean, beanManager);
validateInterceptorDecoratorInjectionPointPassivationCapable(injectionPoint, resolvedBean, beanManager, classBean);
}
}
}
Expand All @@ -267,10 +267,13 @@ private void validateDecorators(BeanManagerImpl beanManager, DecorableBean<?> be
throw ValidatorLogger.LOG.passivatingBeanWithNonserializableDecorator(bean, decorator);
}
}
if (decorator instanceof DecoratorImpl) {
beanManager = ((DecoratorImpl<?>) decorator).getBeanManager();
}
for (InjectionPoint ij : decorator.getInjectionPoints()) {
if (!ij.isDelegate()) {
Bean<?> resolvedBean = beanManager.resolve(beanManager.getBeans(ij));
validateInjectionPointPassivationCapable(ij, resolvedBean, beanManager);
validateInterceptorDecoratorInjectionPointPassivationCapable(ij, resolvedBean, beanManager, bean);
}
}
}
Expand Down Expand Up @@ -457,18 +460,31 @@ private boolean hasScopeMetaAnnotation(Annotation annotation) {
return annotationType.isAnnotationPresent(Scope.class) || annotationType.isAnnotationPresent(NormalScope.class);
}

public void validateInjectionPointPassivationCapable(InjectionPoint ij, Bean<?> resolvedBean, BeanManagerImpl beanManager) {
private boolean isInjectionPointPassivationCapable(InjectionPoint ij, Bean<?> resolvedBean, BeanManagerImpl beanManager) {
if (!Beans.isPassivationCapableDependency(resolvedBean)) {
if (((ij.getMember() instanceof Field) && ij.isTransient())) {
return;
return true;
}
if (ij.getAnnotated() instanceof AnnotatedParameter<?> && ij.getAnnotated().isAnnotationPresent(TransientReference.class)) {
return;
return true;
}
return false;
}
return true;
}

public void validateInjectionPointPassivationCapable(InjectionPoint ij, Bean<?> resolvedBean, BeanManagerImpl beanManager) {
if (!isInjectionPointPassivationCapable(ij, resolvedBean, beanManager)) {
throw ValidatorLogger.LOG.injectionPointHasNonSerializableDependency(ij.getBean(), resolvedBean);
}
}

public void validateInterceptorDecoratorInjectionPointPassivationCapable(InjectionPoint ij, Bean<?> resolvedBean, BeanManagerImpl beanManager, Bean<?> bean) {
if (!isInjectionPointPassivationCapable(ij, resolvedBean, beanManager)) {
throw ValidatorLogger.LOG.interceptorDecoratorInjectionPointHasNonSerializableDependency(bean, ij.getBean(), resolvedBean);
}
}

public void validateDeployment(BeanManagerImpl manager, BeanDeployment deployment) {
validateDecorators(manager.getDecorators(), manager);
validateInterceptors(manager.getInterceptors(), manager);
Expand Down
14 changes: 8 additions & 6 deletions impl/src/main/java/org/jboss/weld/logging/ValidatorLogger.java
Expand Up @@ -27,10 +27,10 @@
import org.jboss.logging.annotations.MessageLogger;
import org.jboss.weld.exceptions.DefinitionException;
import org.jboss.weld.exceptions.DeploymentException;
import org.jboss.weld.exceptions.IllegalArgumentException;
import org.jboss.weld.exceptions.InconsistentSpecializationException;
import org.jboss.weld.exceptions.UnproxyableResolutionException;
import org.jboss.weld.exceptions.UnserializableDependencyException;
import org.jboss.weld.exceptions.IllegalArgumentException;

/**
* Log messages for validation related classes.
Expand Down Expand Up @@ -94,10 +94,10 @@ public String invoke(Object... params) {
@Message(id = 1401, value = "Two beans cannot specialize the same bean {0}", format = Format.MESSAGE_FORMAT)
InconsistentSpecializationException beanSpecializedTooManyTimes(Object param1);

@Message(id = 1402, value = "The bean {0} declared a passivating scope but has a non-serializable interceptor {1}", format = Format.MESSAGE_FORMAT)
@Message(id = 1402, value = "The bean {0} declares a passivating scope but has a non-serializable interceptor {1}", format = Format.MESSAGE_FORMAT)
DeploymentException passivatingBeanWithNonserializableInterceptor(Object param1, Object param2);

@Message(id = 1403, value = "The bean {0} declared a passivating scope but has non-serializable decorator {1}", format = Format.MESSAGE_FORMAT)
@Message(id = 1403, value = "The bean {0} declares a passivating scope but has a non-serializable decorator {1}", format = Format.MESSAGE_FORMAT)
UnserializableDependencyException passivatingBeanWithNonserializableDecorator(Object param1, Object param2);

@Message(id = 1404, value = "The injection point {0} is annotated with @New which cannot be combined with other qualifiers", format = Format.MESSAGE_FORMAT)
Expand Down Expand Up @@ -132,10 +132,10 @@ public String invoke(Object... params) {
* @deprecated Not in use
*/
@Deprecated
@Message(id = 1412, value = "The bean {0} declares passivating scope but the producer returned a non-serializable bean for injection: {1}", format = Format.MESSAGE_FORMAT)
@Message(id = 1412, value = "The bean {0} declares a passivating scope but the producer returned a non-serializable bean for injection: {1}", format = Format.MESSAGE_FORMAT)
String nonSerializableBeanInjectedIntoPassivatingBean(Object param1, Object param2);

@Message(id = 1413, value = "The bean {0} declares passivating scope but has non-passivation-capable dependency {1}", format = Format.MESSAGE_FORMAT)
@Message(id = 1413, value = "The bean {0} declares a passivating scope but has a non-passivation-capable dependency {1}", format = Format.MESSAGE_FORMAT)
UnserializableDependencyException injectionPointHasNonSerializableDependency(Object param1, Object param2);

@Message(id = 1414, value = "Bean name is ambiguous. Name {0} resolves to beans: {1}", format = Format.MESSAGE_FORMAT)
Expand Down Expand Up @@ -351,7 +351,7 @@ public String invoke(Object... params) {
DefinitionException eventMetadataInjectedOutsideOfObserver(Object param1);

@LogMessage(level = Level.WARN)
@Message(id = 1473, value = "javax.enterprise.inject.spi.Bean implementation {0} declared a normal scope but does not implement javax.enterprise.inject.spi.PassivationCapable. It won'''t be possible to inject this bean into a bean with passivating scope (@SessionScoped, @ConversationScoped). This can be fixed by assigning the Bean implementation a unique id by implementing the PassivationCapable interface.", format = Format.MESSAGE_FORMAT)
@Message(id = 1473, value = "javax.enterprise.inject.spi.Bean implementation {0} declared a normal scope but does not implement javax.enterprise.inject.spi.PassivationCapable. It won'''t be possible to inject this bean into a bean with a passivating scope (@SessionScoped, @ConversationScoped). This can be fixed by assigning the Bean implementation a unique id by implementing the PassivationCapable interface.", format = Format.MESSAGE_FORMAT)
void beanNotPassivationCapable(Object param1);

@Message(id = 1474, value = "Class {0} is on the classpath, but was ignored because a class it references was not found: {1}.\n", format = Format.MESSAGE_FORMAT)
Expand All @@ -363,4 +363,6 @@ public String invoke(Object... params) {
@Message(id = 1476, value = "{0} must be @Dependent", format = Format.MESSAGE_FORMAT)
DefinitionException interceptorMustBeDependent(Object param1);

@Message(id = 1477, value = "The bean {0} declares a passivating scope but has a(n) {1} with a non-passivation-capable dependency {2}", format = Format.MESSAGE_FORMAT)
UnserializableDependencyException interceptorDecoratorInjectionPointHasNonSerializableDependency(Object param1, Object param2, Object param3);
}

0 comments on commit 2d6a259

Please sign in to comment.