Indirect specialization (4.3.1) throws InconsistentSpecializationException
--------------------------------------------------------------------------
Key: OWB-279
URL: https://issues.apache.org/jira/browse/OWB-279
Project: OpenWebBeans
Issue Type: Bug
Components: Injection and Lookup
Affects Versions: M3
Reporter: YING WANG
Assignee: Gurkan Erdogdu
I have a list of specializes/extends beans (Car <- CarToyota <- CarToyotaCamry
<- CarToyotaCamryHybird). However the test throws
org.apache.webbeans.exception.inject.InconsistentSpecializationException: More
than one specialized bean for class : class
org.apache.webbeans.newtests.specializes2.CarToyota is enabled in the
deployment.
According to 4.3.1 X,Y,Z case, indirect specialization should work and
CarToyotaCamryHybird should be enabled in the above test case. Please help
review the test case (will upload later) and the following patches.
==============WebBeansUtil.java=======================
/**
* verify a list of beans are directly specialized/extended each other.
*
* @param resolvers
* @return
*/
public static boolean isDirectlySpecialized(Set<Bean<?>> beans) {
ArrayList<AbstractBean<?>> beanList = new ArrayList<AbstractBean<?>>();
for(Bean<?> bb : beans) {
AbstractBean<?>bean = (AbstractBean<?>)bb;
beanList.add(bean);
}
java.util.Collections.sort(beanList, new java.util.Comparator() {
public int compare(Object o1, Object o2) {
AbstractBean<?> b1 = (AbstractBean<?>)o1;
AbstractBean<?> b2 = (AbstractBean<?>)o2;
Class c1 = b1.getReturnType();
Class c2 = b2.getReturnType();
if (c2.isAssignableFrom(c1)) return 1;
if (c1.isAssignableFrom(c2)) return -1;
throw new InconsistentSpecializationException(c1 + "
and " + c2 + "are not assignable to each other." );
}
});
for(int i=0; i<beanList.size() - 1; i++) {
if
(!beanList.get(i).getReturnType().equals(beanList.get(i+1).getReturnType().getSuperclass()))
return false;
}
return true;
}
and in WebBeansUtil.configureSpecializations( ), verify the resolvers are
directly specialized/extended when size > 1.
if(resolvers.size() > 1 && !isDirectlySpecialized(resolvers))
{ throw new InconsistentSpecializationException("More than one
specialized bean for class : " + specializedClass + " is enabled in the
deployment.");
}
==============BeansDeployer.java=======================
added superClassList local variable. If beanClasses contains:
Car, CarToyota(s), Bus, ShoolBus(s), CarFord(s), current logic will not find
CarFord and carToyota will both specialize Car.
protected void checkSpecializations(ScannerService scanner)
{
logger.info(OWBLogConst.INFO_0029);
try
{
Set<Class<?>> beanClasses = scanner.getBeanClasses();
if (beanClasses != null && beanClasses.size() > 0)
{
// make sure we do not have 2 specialized beans shares the same
super class
Class<?> superClass = null;
ArrayList<Class<?>> superClassList = new ArrayList<Class<?>>();
for(Class<?> specialClass : beanClasses)
{
if(AnnotationUtil.hasClassAnnotation(specialClass,
Specializes.class))
{
superClass = specialClass.getSuperclass();
if(superClass.equals(Object.class))
{
throw new
WebBeansConfigurationException(logger.getTokenString(OWBLogConst.EXCEPT_0003) +
specialClass.getName()
+
logger.getTokenString(OWBLogConst.EXCEPT_0004));
}
if
(superClassList.contains(specialClass.getSuperclass()))
{
throw new
InconsistentSpecializationException(logger.getTokenString(OWBLogConst.EXCEPT_0005)
+ superClass.getName());
}
WebBeansUtil.configureSpecializations(specialClass);
}
}
}
// XML Defined Specializations
checkXMLSpecializations();
}
catch(Exception e)
{
throw new WebBeansDeploymentException(e);
}
logger.info(OWBLogConst.INFO_0030);
}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.