1
1
package io .cucumber .java ;
2
2
3
+ import io .cucumber .core .exception .UnrecoverableExceptions ;
4
+ import io .cucumber .core .logging .Logger ;
5
+ import io .cucumber .core .logging .LoggerFactory ;
6
+
3
7
import java .lang .annotation .Annotation ;
4
8
import java .lang .reflect .Method ;
5
9
import java .lang .reflect .Modifier ;
9
13
10
14
final class MethodScanner {
11
15
16
+ private static final Logger log = LoggerFactory .getLogger (MethodScanner .class );
17
+
12
18
private MethodScanner () {
13
19
}
14
20
@@ -21,11 +27,29 @@ static void scan(Class<?> aClass, BiConsumer<Method, Annotation> consumer) {
21
27
if (!isInstantiable (aClass )) {
22
28
return ;
23
29
}
24
- for (Method method : aClass . getMethods ( )) {
30
+ for (Method method : safelyGetMethods ( aClass )) {
25
31
scan (consumer , aClass , method );
26
32
}
27
33
}
28
34
35
+ private static Method [] safelyGetMethods (Class <?> aClass ) {
36
+ try {
37
+ return aClass .getMethods ();
38
+ } catch (Throwable e ) {
39
+ UnrecoverableExceptions .rethrowIfUnrecoverable (e );
40
+ log .warn (e , () -> "" +
41
+ "Failed to load methods of class '" + aClass .getName () + "'.\n " +
42
+ "By default Cucumber scans the classpath for step definitions.\n " +
43
+ "You can restrict this by configuring the glue path.\n " +
44
+ "\n " +
45
+ "Examples:\n " +
46
+ " - @CucumberOptions(glue = \" com.example.application\" )\n " +
47
+ " - src/test/resources/junit-platform.properties cucumber.glue=com.example.application\n " +
48
+ " - src/test/resources/cucumber.properties cucumber.glue=com.example.application\n " );
49
+ }
50
+ return new Method [0 ];
51
+ }
52
+
29
53
private static boolean isInstantiable (Class <?> clazz ) {
30
54
boolean isNonStaticInnerClass = !Modifier .isStatic (clazz .getModifiers ()) && clazz .getEnclosingClass () != null ;
31
55
return Modifier .isPublic (clazz .getModifiers ()) && !Modifier .isAbstract (clazz .getModifiers ())
0 commit comments