Skip to content

Commit

Permalink
WELD-1081 Weld crashes when attempting to read malformed class names
Browse files Browse the repository at this point in the history
  • Loading branch information
jharting committed Mar 20, 2013
1 parent cab0792 commit 2085a12
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
Expand Up @@ -32,6 +32,7 @@
import org.jboss.weld.exceptions.DefinitionException;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.util.collections.WeldCollections;
import org.jboss.weld.util.reflection.Reflections;

/**
* Basic {@link InjectionTarget} implementation. The implementation supports:
Expand Down Expand Up @@ -75,7 +76,7 @@ public BasicInjectionTarget(EnhancedAnnotatedType<T> type, Bean<T> bean, BeanMan
}

protected void checkType(EnhancedAnnotatedType<T> type) {
if (type.isAnonymousClass() || (type.isMemberClass() && !type.isStatic())) {
if (Reflections.isNonStaticInnerClass(type.getJavaClass())) {
throw new DefinitionException(SIMPLE_BEAN_AS_NON_STATIC_INNER_CLASS_NOT_ALLOWED, type);
}
}
Expand Down
2 changes: 1 addition & 1 deletion impl/src/main/java/org/jboss/weld/util/Beans.java
Expand Up @@ -496,7 +496,7 @@ public static Set<Type> getTypedTypes(Map<Class<?>, Type> typeClosure, Class<?>
public static boolean isTypeManagedBeanOrDecoratorOrInterceptor(AnnotatedType<?> annotatedType) {
Class<?> javaClass = annotatedType.getJavaClass();
return !javaClass.isEnum() && !Extension.class.isAssignableFrom(javaClass)
&& (javaClass.getEnclosingClass() == null || (Reflections.isStatic(javaClass) && javaClass.isMemberClass()))
&& !Reflections.isNonStaticInnerClass(javaClass)
&& !Reflections.isParamerterizedTypeWithWildcard(javaClass)
&& hasSimpleCdiConstructor(annotatedType);
}
Expand Down
13 changes: 11 additions & 2 deletions impl/src/main/java/org/jboss/weld/util/reflection/Reflections.java
Expand Up @@ -76,7 +76,7 @@ public static Map<Class<?>, Type> buildTypeMap(Set<Type> types) {
public static boolean isCacheable(Collection<Annotation> annotations) {
for (Annotation qualifier : annotations) {
Class<?> clazz = qualifier.getClass();
if (clazz.isAnonymousClass() || (clazz.isMemberClass() && isStatic(clazz))) {
if (isNonStaticInnerClass(clazz)) {
return false;
}
}
Expand All @@ -86,7 +86,7 @@ public static boolean isCacheable(Collection<Annotation> annotations) {
public static boolean isCacheable(Annotation[] annotations) {
for (Annotation qualifier : annotations) {
Class<?> clazz = qualifier.getClass();
if (clazz.isAnonymousClass() || (clazz.isMemberClass() && isStatic(clazz))) {
if (isNonStaticInnerClass(clazz)) {
return false;
}
}
Expand Down Expand Up @@ -389,4 +389,13 @@ public static boolean isUnboundedWildcard(Type type) {
private static boolean isEmptyBoundArray(Type[] bounds) {
return bounds == null || bounds.length == 0 || (bounds.length == 1 && Object.class.equals(bounds[0]));
}

/**
* @see https://issues.jboss.org/browse/WELD-1081
*/
public static boolean isNonStaticInnerClass(Class<?> javaClass) {
return javaClass.getEnclosingConstructor() != null
|| javaClass.getEnclosingMethod() != null
|| (javaClass.getEnclosingClass() != null && !Reflections.isStatic(javaClass));
}
}

0 comments on commit 2085a12

Please sign in to comment.