Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iss1458: added sanity checker for the method that detects point cut t… #1481

Merged
merged 2 commits into from
Mar 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May it make sense to add some information about the declaring class of the method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, will add

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks. For me this looks good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattrjacobs merge ?

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";
}
}

}