Skip to content
Permalink
Browse files

WELD-2216 provide additional info for Instance.get() deployment probl…

…ems.
  • Loading branch information...
tremes authored and mkouba committed Aug 9, 2016
1 parent 5a638ba commit 43c6323a24b162d452de4eb37162d264c45e57de
@@ -50,6 +50,7 @@
import org.jboss.weld.resolution.Resolvable;
import org.jboss.weld.resolution.ResolvableBuilder;
import org.jboss.weld.resolution.TypeSafeBeanResolver;
import org.jboss.weld.util.InjectionPoints;
import org.jboss.weld.util.Preconditions;
import org.jboss.weld.util.collections.WeldCollections;
import org.jboss.weld.util.reflection.Formats;
@@ -101,9 +102,15 @@ public T get() {
if (bean != null) {
return getBeanInstance(bean);
} else if (isUnsatisfied()) {
throw BeanManagerLogger.LOG.unresolvableElement("Type: " + getType() + "; Qualifiers: " + getQualifiers());
throw BeanManagerLogger.LOG.injectionPointHasUnsatisfiedDependencies(
Formats.formatAnnotations(ip.getQualifiers()),
Formats.formatInjectionPointType(ip.getType()),
InjectionPoints.getUnsatisfiedDependenciesAdditionalInfo(ip, getBeanManager()));
} else {
throw BeanManagerLogger.LOG.ambiguousBeansForDependency(WeldCollections.toMultiRowString(allBeans));
throw BeanManagerLogger.LOG.injectionPointHasAmbiguousDependencies(
Formats.formatAnnotations(ip.getQualifiers()),
Formats.formatInjectionPointType(ip.getType()),
WeldCollections.toMultiRowString(allBeans));
}
}

@@ -84,6 +84,7 @@
import org.jboss.weld.bootstrap.spi.BeansXml;
import org.jboss.weld.bootstrap.spi.Metadata;
import org.jboss.weld.ejb.EJBApiAbstraction;
import org.jboss.weld.exceptions.AmbiguousResolutionException;
import org.jboss.weld.exceptions.DefinitionException;
import org.jboss.weld.exceptions.DeploymentException;
import org.jboss.weld.exceptions.UnproxyableResolutionException;
@@ -92,7 +93,6 @@
import org.jboss.weld.interceptor.reader.PlainInterceptorFactory;
import org.jboss.weld.interceptor.spi.metadata.InterceptorClassMetadata;
import org.jboss.weld.interceptor.spi.model.InterceptionModel;
import org.jboss.weld.literal.AnyLiteral;
import org.jboss.weld.literal.DecoratedLiteral;
import org.jboss.weld.literal.DefaultLiteral;
import org.jboss.weld.literal.InterceptedLiteral;
@@ -105,6 +105,7 @@
import org.jboss.weld.util.BeanMethods;
import org.jboss.weld.util.Beans;
import org.jboss.weld.util.Decorators;
import org.jboss.weld.util.InjectionPoints;
import org.jboss.weld.util.JtaApiAbstraction;
import org.jboss.weld.util.Proxies;
import org.jboss.weld.util.collections.Multimap;
@@ -352,11 +353,11 @@ public void validateInjectionPointForDeploymentProblems(InjectionPoint ij, Bean<
Set<?> resolvedBeans = beanManager.getBeanResolver().resolve(beanManager.getBeans(ij));
if (!isInjectionPointSatisfied(ij, resolvedBeans, beanManager)) {
throw ValidatorLogger.LOG.injectionPointHasUnsatisfiedDependencies(
ij,
Formats.formatAnnotations(ij.getQualifiers()),
Formats.formatInjectionPointType(ij.getType()),
Formats.formatAsStackTraceElement(ij),
getUnsatisfiedDependenciesAdditionalInfo(ij, beanManager));
ij,
Formats.formatAnnotations(ij.getQualifiers()),
Formats.formatInjectionPointType(ij.getType()),
Formats.formatAsStackTraceElement(ij),
InjectionPoints.getUnsatisfiedDependenciesAdditionalInfo(ij, beanManager));
}
if (resolvedBeans.size() > 1) {
throw ValidatorLogger.LOG.injectionPointHasAmbiguousDependencies(
@@ -381,26 +382,6 @@ public void validateInjectionPointForDeploymentProblems(InjectionPoint ij, Bean<
}
}

private String getUnsatisfiedDependenciesAdditionalInfo(InjectionPoint ij, BeanManagerImpl beanManager) {
Set<Bean<?>> beansMatchedByType = beanManager.getBeans(ij.getType(), AnyLiteral.INSTANCE);
if (beansMatchedByType.isEmpty()) {
Class<?> rawType = Reflections.getRawType(ij.getType());
if (rawType != null) {
MissingDependenciesRegistry missingDependenciesRegistry = beanManager.getServices().get(MissingDependenciesRegistry.class);
String missingDependency = missingDependenciesRegistry.getMissingDependencyForClass(rawType.getName());
if (missingDependency != null) {
return ValidatorLogger.LOG.unsatisfiedDependencyBecauseClassIgnored(
rawType.getName(),
missingDependency);
}
}
} else {
return ValidatorLogger.LOG.unsatisfiedDependencyBecauseQualifiersDontMatch(
WeldCollections.toMultiRowString(beansMatchedByType));
}
return "";
}

public void validateProducers(Collection<Producer<?>> producers, BeanManagerImpl beanManager) {
for (Producer<?> producer : producers) {
validateProducer(producer, beanManager);
@@ -922,7 +903,15 @@ private static void reallyValidatePseudoScopedBean(Bean<?> bean, BeanManagerImpl

private static void validatePseudoScopedInjectionPoint(InjectionPoint ij, BeanManagerImpl beanManager, Set<Object> dependencyPath, Set<Bean<?>> validatedBeans) {
Set<Bean<?>> resolved = beanManager.getBeans(ij);
Bean<?> bean = beanManager.resolve(resolved);
Bean<?> bean = null;
try {
bean = beanManager.resolve(resolved);
} catch (AmbiguousResolutionException ex) {
throw ValidatorLogger.LOG.injectionPointHasAmbiguousDependencies(ij, Formats.formatAnnotations(ij.getQualifiers()),
Formats.formatInjectionPointType(ij.getType()),
Formats.formatAsStackTraceElement(ij),
WeldCollections.toMultiRowString(resolved));
}
if (bean != null) {
if (!(bean instanceof AbstractBuiltInBean<?>)) {
if (!ij.isDelegate()) {
@@ -121,6 +121,12 @@
@Message(id = 1333, value = "BeanManager method {0} is not available after shutdown", format = Format.MESSAGE_FORMAT)
IllegalStateException methodNotAvailableAfterShutdown(Object param1);

@Message(id = 1334, value = "Unsatisfied dependencies for type {1} with qualifiers {0} {2}", format = Format.MESSAGE_FORMAT)
UnsatisfiedResolutionException injectionPointHasUnsatisfiedDependencies(Object param1, Object param2, Object param3);

@Message(id = 1335, value = "Ambiguous dependencies for type {1} with qualifiers {0}\n Possible dependencies: {2}", format = Format.MESSAGE_FORMAT)
AmbiguousResolutionException injectionPointHasAmbiguousDependencies(Object param1, Object param2, Object param3);

// Last message id used was 1335

}
@@ -26,6 +26,7 @@
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.InjectionPoint;

import org.jboss.weld.bootstrap.MissingDependenciesRegistry;
import org.jboss.weld.injection.MethodInjectionPoint;
import org.jboss.weld.injection.FieldInjectionPoint;
import org.jboss.weld.injection.ParameterInjectionPoint;
@@ -34,7 +35,11 @@
import org.jboss.weld.injection.attributes.ForwardingParameterInjectionPointAttributes;
import org.jboss.weld.injection.attributes.SpecialParameterInjectionPoint;
import org.jboss.weld.injection.attributes.WeldInjectionPointAttributes;
import org.jboss.weld.literal.AnyLiteral;
import org.jboss.weld.logging.ValidatorLogger;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.util.collections.ImmutableSet;
import org.jboss.weld.util.collections.WeldCollections;
import org.jboss.weld.util.reflection.Reflections;

/**
@@ -103,4 +108,24 @@ public static boolean isInjectableReferenceLookupOptimizationAllowed(Bean<?> bea
.equals(resolvedBean.getScope())));
}

public static String getUnsatisfiedDependenciesAdditionalInfo(InjectionPoint ij, BeanManagerImpl beanManager) {
Set<Bean<?>> beansMatchedByType = beanManager.getBeans(ij.getType(), AnyLiteral.INSTANCE);
if (beansMatchedByType.isEmpty()) {
Class<?> rawType = Reflections.getRawType(ij.getType());
if (rawType != null) {
MissingDependenciesRegistry missingDependenciesRegistry = beanManager.getServices().get(MissingDependenciesRegistry.class);
String missingDependency = missingDependenciesRegistry.getMissingDependencyForClass(rawType.getName());
if (missingDependency != null) {
return ValidatorLogger.LOG.unsatisfiedDependencyBecauseClassIgnored(
rawType.getName(),
missingDependency);
}
}
} else {
return ValidatorLogger.LOG.unsatisfiedDependencyBecauseQualifiersDontMatch(
WeldCollections.toMultiRowString(beansMatchedByType));
}
return "";
}

}

0 comments on commit 43c6323

Please sign in to comment.
You can’t perform that action at this time.