Skip to content

Commit 8b2de49

Browse files
authored
Merge pull request Netflix#1481 from dmgcodevil/iss-1458
iss1458: added sanity checker for the method that detects point cut t…
2 parents de12cf2 + 943c10d commit 8b2de49

File tree

2 files changed

+86
-1
lines changed

2 files changed

+86
-1
lines changed

hystrix-contrib/hystrix-javanica/src/main/java/com/netflix/hystrix/contrib/javanica/aop/aspectj/HystrixCommandAspect.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353

5454
import static com.netflix.hystrix.contrib.javanica.utils.AopUtils.getDeclaredMethod;
5555
import static com.netflix.hystrix.contrib.javanica.utils.AopUtils.getMethodFromTarget;
56+
import static com.netflix.hystrix.contrib.javanica.utils.AopUtils.getMethodInfo;
5657
import static com.netflix.hystrix.contrib.javanica.utils.EnvUtils.isCompileWeaving;
5758
import static com.netflix.hystrix.contrib.javanica.utils.ajc.AjcUtils.getAjcMethodAroundAdvice;
5859

@@ -272,7 +273,14 @@ private enum HystrixPointcutType {
272273
COLLAPSER;
273274

274275
static HystrixPointcutType of(Method method) {
275-
return method.isAnnotationPresent(HystrixCommand.class) ? COMMAND : COLLAPSER;
276+
if (method.isAnnotationPresent(HystrixCommand.class)) {
277+
return COMMAND;
278+
} else if (method.isAnnotationPresent(HystrixCollapser.class)) {
279+
return COLLAPSER;
280+
} else {
281+
String methodInfo = getMethodInfo(method);
282+
throw new IllegalStateException("'https://github.com/Netflix/Hystrix/issues/1458' - no valid annotation found for: \n" + methodInfo);
283+
}
276284
}
277285
}
278286

hystrix-contrib/hystrix-javanica/src/main/java/com/netflix/hystrix/contrib/javanica/utils/AopUtils.java

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import java.io.IOException;
2525
import java.lang.annotation.Annotation;
2626
import java.lang.reflect.Method;
27+
import java.lang.reflect.Modifier;
28+
import java.lang.reflect.Type;
2729

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

128+
public static String getMethodInfo(Method m) {
129+
StringBuilder info = new StringBuilder();
130+
info.append("Method signature:").append("\n");
131+
info.append(m.toGenericString()).append("\n");
132+
133+
info.append("Declaring class:\n");
134+
info.append(m.getDeclaringClass().getCanonicalName()).append("\n");
135+
136+
info.append("\nFlags:").append("\n");
137+
info.append("Bridge=").append(m.isBridge()).append("\n");
138+
info.append("Synthetic=").append(m.isSynthetic()).append("\n");
139+
info.append("Final=").append(Modifier.isFinal(m.getModifiers())).append("\n");
140+
info.append("Native=").append(Modifier.isNative(m.getModifiers())).append("\n");
141+
info.append("Synchronized=").append(Modifier.isSynchronized(m.getModifiers())).append("\n");
142+
info.append("Abstract=").append(Modifier.isAbstract(m.getModifiers())).append("\n");
143+
info.append("AccessLevel=").append(getAccessLevel(m.getModifiers())).append("\n");
144+
145+
info.append("\nReturn Type: \n");
146+
info.append("ReturnType=").append(m.getReturnType()).append("\n");
147+
info.append("GenericReturnType=").append(m.getGenericReturnType()).append("\n");
148+
149+
info.append("\nParameters:");
150+
Class<?>[] pType = m.getParameterTypes();
151+
Type[] gpType = m.getGenericParameterTypes();
152+
if (pType.length != 0) {
153+
info.append("\n");
154+
} else {
155+
info.append("empty\n");
156+
}
157+
for (int i = 0; i < pType.length; i++) {
158+
info.append("parameter [").append(i).append("]:\n");
159+
info.append("ParameterType=").append(pType[i]).append("\n");
160+
info.append("GenericParameterType=").append(gpType[i]).append("\n");
161+
}
162+
163+
info.append("\nExceptions:");
164+
Class<?>[] xType = m.getExceptionTypes();
165+
Type[] gxType = m.getGenericExceptionTypes();
166+
if (xType.length != 0) {
167+
info.append("\n");
168+
} else {
169+
info.append("empty\n");
170+
}
171+
for (int i = 0; i < xType.length; i++) {
172+
info.append("exception [").append(i).append("]:\n");
173+
info.append("ExceptionType=").append(xType[i]).append("\n");
174+
info.append("GenericExceptionType=").append(gxType[i]).append("\n");
175+
}
176+
177+
info.append("\nAnnotations:");
178+
if (m.getAnnotations().length != 0) {
179+
info.append("\n");
180+
} else {
181+
info.append("empty\n");
182+
}
183+
184+
for (int i = 0; i < m.getAnnotations().length; i++) {
185+
info.append("annotation[").append(i).append("]=").append(m.getAnnotations()[i]).append("\n");
186+
}
187+
188+
return info.toString();
189+
}
190+
191+
private static String getAccessLevel(int modifiers) {
192+
if (Modifier.isPublic(modifiers)) {
193+
return "public";
194+
} else if (Modifier.isProtected(modifiers)) {
195+
return "protected";
196+
} else if (Modifier.isPrivate(modifiers)) {
197+
return "private";
198+
} else {
199+
return "default";
200+
}
201+
}
202+
126203
}

0 commit comments

Comments
 (0)