Skip to content

Commit

Permalink
WBRI-354
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@3483 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Aug 13, 2009
1 parent b6600d2 commit 8fdaad7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
8 changes: 6 additions & 2 deletions impl/src/main/java/org/jboss/webbeans/Validator.java
Expand Up @@ -141,7 +141,11 @@ public void validateInjectionPoint(InjectionPoint ij, BeanManagerImpl beanManage
{
throw new DefinitionException("The injection point " + ij + " is annotated with @New which cannot be combined with other binding types");
}
if (!Dependent.class.equals(ij.getBean().getScopeType()) && ij.getType().equals(InjectionPoint.class))
if (ij.getType().equals(InjectionPoint.class) && ij.getBean() == null)
{
throw new DefinitionException("Cannot inject an Injection point into a class which isn't a bean " + ij);
}
if (ij.getType().equals(InjectionPoint.class) && !Dependent.class.equals(ij.getBean().getScopeType()))
{
throw new DefinitionException("Cannot inject an InjectionPoint into a non @Dependent scoped bean " + ij);
}
Expand Down Expand Up @@ -186,7 +190,7 @@ public void validateInjectionPoint(InjectionPoint ij, BeanManagerImpl beanManage
{
throw new NullableDependencyException("The injection point " + ij + " has nullable dependencies");
}
if (Beans.isPassivatingScope(ij.getBean(), beanManager) && (!ij.isTransient()) && !Beans.isPassivationCapableBean(resolvedBean))
if (ij.getBean() != null && Beans.isPassivatingScope(ij.getBean(), beanManager) && (!ij.isTransient()) && !Beans.isPassivationCapableBean(resolvedBean))
{
validateInjectionPointPassivationCapable(ij, resolvedBean, beanManager);
}
Expand Down
Expand Up @@ -3,8 +3,10 @@
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.inject.spi.InjectionTarget;

import org.jboss.metadata.validation.ValidationException;
import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.webbeans.test.AbstractWebBeansTest;
import org.testng.Assert;
Expand All @@ -27,6 +29,25 @@ public void testNonContextual() throws Exception
Assert.assertNotNull(external.bean);
}

@Test
public void validateNonContextual() throws Exception
{
NonContextual<External> nonContextual = new NonContextual<External>(getCurrentManager(), External.class);

for (InjectionPoint point : nonContextual.it.getInjectionPoints())
{
try
{
getCurrentManager().validate(point);
}
catch(ValidationException e)
{
Assert.fail("Should have been valid");
}
}
}


public class NonContextual<T> {

final InjectionTarget<T> it;
Expand Down

0 comments on commit 8fdaad7

Please sign in to comment.