Skip to content

Commit

Permalink
Fixed recusion in reflection utils
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan committed May 8, 2015
1 parent 017f52a commit cca88c3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
17 changes: 12 additions & 5 deletions src/main/java/net/engio/mbassy/common/ReflectionUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
import java.util.ArrayDeque;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Set;

/**
Expand All @@ -16,8 +19,13 @@
public class ReflectionUtils
{

public static List<Method> getMethods( IPredicate<Method> condition, Class<?> target ) {
List<Method> methods = new LinkedList<Method>();
public static Collection<Method> getMethods( IPredicate<Method> condition, Class<?> target ) {
Collection<Method> methods = new ArrayDeque<Method>();
getMethods(condition, target, methods);
return methods;
}

private static void getMethods( IPredicate<Method> condition, Class<?> target, Collection<Method> methods ) {
try {
for ( Method method : target.getDeclaredMethods() ) {
if ( condition.apply( method ) ) {
Expand All @@ -29,9 +37,8 @@ public static List<Method> getMethods( IPredicate<Method> condition, Class<?> ta
//nop
}
if ( !target.equals( Object.class ) ) {
methods.addAll( getMethods( condition, target.getSuperclass() ) );
getMethods( condition, target.getSuperclass(), methods );
}
return methods;
}

/**
Expand Down Expand Up @@ -80,7 +87,7 @@ public static void collectInterfaces( Class from, Set<Class> accumulator ) {
}
}

public static boolean containsOverridingMethod( final List<Method> allMethods, final Method methodToCheck ) {
public static boolean containsOverridingMethod( final Collection<Method> allMethods, final Method methodToCheck ) {
for ( Method method : allMethods ) {
if ( isOverriddenBy( methodToCheck, method ) ) {
return true;
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/net/engio/mbassy/listener/MetadataReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import net.engio.mbassy.subscription.MessageEnvelope;

import java.lang.reflect.Method;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;

/**
* The meta data reader is responsible for parsing and validating message handler configurations.
Expand Down Expand Up @@ -57,7 +59,7 @@ private IMessageFilter[] getFilter(Handler subscription) {
public MessageListener getMessageListener(Class target) {
MessageListener listenerMetadata = new MessageListener(target);
// get all handlers (this will include all (inherited) methods directly annotated using @Handler)
List<Method> allHandlers = ReflectionUtils.getMethods(AllMessageHandlers, target);
Collection<Method> allHandlers = ReflectionUtils.getMethods(AllMessageHandlers, target);
// retain only those that are at the bottom of their respective class hierarchy (deepest overriding method)
List<Method> bottomMostHandlers = new LinkedList<Method>();
for (Method handler : allHandlers) {
Expand Down

0 comments on commit cca88c3

Please sign in to comment.