Author: struberg
Date: Thu Jun 1 21:34:34 2017
New Revision: 1797270
URL: http://svn.apache.org/viewvc?rev=1797270&view=rev
Log:
OWB-1189 implement check for duplicate Qualifiers
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnnotationManager.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventMetadataImpl.java
openwebbeans/trunk/webbeans-tck/standalone-suite.xml
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnnotationManager.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnnotationManager.java?rev=1797270&r1=1797269&r2=1797270&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnnotationManager.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnnotationManager.java
Thu Jun 1 21:34:34 2017
@@ -47,6 +47,7 @@ import javax.inject.Scope;
import javax.interceptor.InterceptorBinding;
import java.lang.annotation.Annotation;
+import java.lang.annotation.Repeatable;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
@@ -74,12 +75,15 @@ public final class AnnotationManager
private final BeanManagerImpl beanManagerImpl;
private final WebBeansContext webBeansContext;
+ private final boolean strictValidation;
+
// No instantiate
public AnnotationManager(WebBeansContext context)
{
webBeansContext = context;
beanManagerImpl = context.getBeanManagerImpl();
+ strictValidation =
context.getOpenWebBeansConfiguration().strictDynamicValidation();
}
public Annotation getDeclaredScopeAnnotation(Class<?> beanClass)
@@ -429,8 +433,23 @@ public final class AnnotationManager
*/
public void checkQualifierConditions(Set<Annotation> qualifierAnnots)
{
+ Set<Class<? extends Annotation>> usedQualifiers = strictValidation ?
new HashSet<>(qualifierAnnots.size()) : null;
+
for (Annotation ann : qualifierAnnots)
{
+ if (usedQualifiers != null &&
usedQualifiers.contains(ann.annotationType()))
+ {
+ if (ann.annotationType().getAnnotation(Repeatable.class) ==
null)
+ {
+ throw new IllegalArgumentException("Qualifier list must
not contain multiple annotations or the same non-Repeatable type: "
+ + ann.annotationType().getName());
+ }
+ }
+ if (usedQualifiers != null)
+ {
+ usedQualifiers.add(ann.annotationType());
+ }
+
checkQualifierConditions(ann);
}
}
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java?rev=1797270&r1=1797269&r2=1797270&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
Thu Jun 1 21:34:34 2017
@@ -93,7 +93,7 @@ public class WebBeansContext
private final PluginLoader pluginLoader = new PluginLoader();
private final SerializableBeanVault serializableBeanVault = new
SerializableBeanVault();
private final StereoTypeManager stereoTypeManager = new
StereoTypeManager();
- private final AnnotationManager annotationManager = new
AnnotationManager(this);
+ private final AnnotationManager annotationManager;
private final InjectionPointFactory injectionPointFactory = new
InjectionPointFactory(this);
private final InterceptorUtil interceptorUtil = new InterceptorUtil(this);
private final SecurityService securityService;
@@ -122,6 +122,7 @@ public class WebBeansContext
private WebBeansContext(Map<Class<?>, Object> initialServices,
OpenWebBeansConfiguration openWebBeansConfiguration)
{
this.openWebBeansConfiguration = openWebBeansConfiguration != null ?
openWebBeansConfiguration : new OpenWebBeansConfiguration();
+ annotationManager = new AnnotationManager(this);
//pluggable service-loader
if (initialServices == null ||
!initialServices.containsKey(LoaderService.class))
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventMetadataImpl.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventMetadataImpl.java?rev=1797270&r1=1797269&r2=1797270&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventMetadataImpl.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventMetadataImpl.java
Thu Jun 1 21:34:34 2017
@@ -67,11 +67,12 @@ public class EventMetadataImpl implement
}
else
{
- completeQualifiers = new
HashSet<Annotation>(Arrays.asList(qualifiers));
+ completeQualifiers = new HashSet<>(Arrays.asList(qualifiers));
if (completeQualifiers.size() != qualifiers.length)
{
throw new IllegalArgumentException("duplicate qualifier");
}
+
if (!completeQualifiers.contains(AnyLiteral.INSTANCE))
{
completeQualifiers.add(AnyLiteral.INSTANCE);
Modified: openwebbeans/trunk/webbeans-tck/standalone-suite.xml
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-tck/standalone-suite.xml?rev=1797270&r1=1797269&r2=1797270&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-tck/standalone-suite.xml (original)
+++ openwebbeans/trunk/webbeans-tck/standalone-suite.xml Thu Jun 1 21:34:34
2017
@@ -127,12 +127,12 @@
</class>
<!-- overreachingly defined checks for repeatable qualifiers -->
- <class name="org.jboss.cdi.tck.tests.event.select.SelectEventTest">
+ <!-- <class
name="org.jboss.cdi.tck.tests.event.select.SelectEventTest">
<methods>
<exclude
name="testEventSelectThrowsExceptionForDuplicateBindingType"/>
<exclude
name="testEventSelectWithSubtypeThrowsExceptionForDuplicateBindingType"/>
</methods>
- </class>
+ </class>-->