Skip to content

Commit

Permalink
Merge pull request Netflix#1481 from dmgcodevil/iss-1458
Browse files Browse the repository at this point in the history
iss1458: added sanity checker for the method that detects point cut t…
  • Loading branch information
mattrjacobs authored Mar 1, 2017
2 parents de12cf2 + 943c10d commit 8b2de49
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

import static com.netflix.hystrix.contrib.javanica.utils.AopUtils.getDeclaredMethod;
import static com.netflix.hystrix.contrib.javanica.utils.AopUtils.getMethodFromTarget;
import static com.netflix.hystrix.contrib.javanica.utils.AopUtils.getMethodInfo;
import static com.netflix.hystrix.contrib.javanica.utils.EnvUtils.isCompileWeaving;
import static com.netflix.hystrix.contrib.javanica.utils.ajc.AjcUtils.getAjcMethodAroundAdvice;

Expand Down Expand Up @@ -272,7 +273,14 @@ private enum HystrixPointcutType {
COLLAPSER;

static HystrixPointcutType of(Method method) {
return method.isAnnotationPresent(HystrixCommand.class) ? COMMAND : COLLAPSER;
if (method.isAnnotationPresent(HystrixCommand.class)) {
return COMMAND;
} else if (method.isAnnotationPresent(HystrixCollapser.class)) {
return COLLAPSER;
} else {
String methodInfo = getMethodInfo(method);
throw new IllegalStateException("'https://github.com/Netflix/Hystrix/issues/1458' - no valid annotation found for: \n" + methodInfo);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;

/**
* Provides common methods to retrieve information from JoinPoint and not only.
Expand Down Expand Up @@ -123,4 +125,79 @@ public static <T extends Annotation> Optional<T> getAnnotation(Class<?> type, Cl
return Optional.absent();
}

public static String getMethodInfo(Method m) {
StringBuilder info = new StringBuilder();
info.append("Method signature:").append("\n");
info.append(m.toGenericString()).append("\n");

info.append("Declaring class:\n");
info.append(m.getDeclaringClass().getCanonicalName()).append("\n");

info.append("\nFlags:").append("\n");
info.append("Bridge=").append(m.isBridge()).append("\n");
info.append("Synthetic=").append(m.isSynthetic()).append("\n");
info.append("Final=").append(Modifier.isFinal(m.getModifiers())).append("\n");
info.append("Native=").append(Modifier.isNative(m.getModifiers())).append("\n");
info.append("Synchronized=").append(Modifier.isSynchronized(m.getModifiers())).append("\n");
info.append("Abstract=").append(Modifier.isAbstract(m.getModifiers())).append("\n");
info.append("AccessLevel=").append(getAccessLevel(m.getModifiers())).append("\n");

info.append("\nReturn Type: \n");
info.append("ReturnType=").append(m.getReturnType()).append("\n");
info.append("GenericReturnType=").append(m.getGenericReturnType()).append("\n");

info.append("\nParameters:");
Class<?>[] pType = m.getParameterTypes();
Type[] gpType = m.getGenericParameterTypes();
if (pType.length != 0) {
info.append("\n");
} else {
info.append("empty\n");
}
for (int i = 0; i < pType.length; i++) {
info.append("parameter [").append(i).append("]:\n");
info.append("ParameterType=").append(pType[i]).append("\n");
info.append("GenericParameterType=").append(gpType[i]).append("\n");
}

info.append("\nExceptions:");
Class<?>[] xType = m.getExceptionTypes();
Type[] gxType = m.getGenericExceptionTypes();
if (xType.length != 0) {
info.append("\n");
} else {
info.append("empty\n");
}
for (int i = 0; i < xType.length; i++) {
info.append("exception [").append(i).append("]:\n");
info.append("ExceptionType=").append(xType[i]).append("\n");
info.append("GenericExceptionType=").append(gxType[i]).append("\n");
}

info.append("\nAnnotations:");
if (m.getAnnotations().length != 0) {
info.append("\n");
} else {
info.append("empty\n");
}

for (int i = 0; i < m.getAnnotations().length; i++) {
info.append("annotation[").append(i).append("]=").append(m.getAnnotations()[i]).append("\n");
}

return info.toString();
}

private static String getAccessLevel(int modifiers) {
if (Modifier.isPublic(modifiers)) {
return "public";
} else if (Modifier.isProtected(modifiers)) {
return "protected";
} else if (Modifier.isPrivate(modifiers)) {
return "private";
} else {
return "default";
}
}

}

0 comments on commit 8b2de49

Please sign in to comment.