Skip to content

Commit 4eaf0d4

Browse files
committed
#154, RunCukesTest.scala uses ScalaBackend.loadGlue which calls ClasspathResourceLoader().instantiateSubclasses which didn't check if the class had a valid constructor given the arguments. ScalaDslTest.scala holds multiple internal ScalaDsl instances which are compiled to classes implementing ScalaDsl but with no valid constructor. These were being picked up by the ClasspathResourceLoader causing the RunCukesTest to fail at load time
1 parent baca12b commit 4eaf0d4

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

core/src/main/java/cucumber/io/ClasspathResourceLoader.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public <T> T instantiateExactlyOneSubclass(Class<T> parentType, String packagePa
4444
public <T> Collection<? extends T> instantiateSubclasses(Class<T> parentType, String packagePath, Class[] constructorParams, Object[] constructorArgs) {
4545
Collection<T> result = new HashSet<T>();
4646
for (Class<? extends T> clazz : getDescendants(parentType, packagePath)) {
47-
if (Utils.isInstantiable(clazz)) {
47+
if (Utils.isInstantiable(clazz) && Utils.hasConstructor(clazz, constructorParams)) {
4848
result.add(newInstance(constructorParams, constructorArgs, clazz));
4949
}
5050
}

core/src/main/java/cucumber/runtime/Utils.java

+9
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ public static <T> List<T> listOf(int size, T obj) {
1717
public static boolean isInstantiable(Class<?> clazz) {
1818
return Modifier.isPublic(clazz.getModifiers()) && !Modifier.isAbstract(clazz.getModifiers());
1919
}
20+
21+
public static boolean hasConstructor(Class<?> clazz, Class[] paramTypes) {
22+
try {
23+
clazz.getConstructor(paramTypes);
24+
return true;
25+
} catch (NoSuchMethodException e) {
26+
return false;
27+
}
28+
}
2029

2130
public static String packagePath(Class clazz) {
2231
return packagePath(packageName(clazz.getName()));

pom.xml

+2-3
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,11 @@
6060
<artifactId>cucumber-picocontainer</artifactId>
6161
<version>${project.version}</version>
6262
</dependency>
63-
<!-- Not cooking scala, should not include it in the depends
6463
<dependency>
6564
<groupId>info.cukes</groupId>
6665
<artifactId>cucumber-scala</artifactId>
6766
<version>${project.version}</version>
68-
</dependency> -->
67+
</dependency>
6968
<dependency>
7069
<groupId>info.cukes</groupId>
7170
<artifactId>gherkin</artifactId>
@@ -254,8 +253,8 @@
254253
<module>rhino</module>
255254
<module>java</module>
256255
<module>clojure</module>
256+
<module>scala</module>
257257

258-
<!--<module>scala</module>-->
259258
<!--<module>openejb</module>-->
260259
</modules>
261260

scala/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<groupId>info.cukes</groupId>
99
<artifactId>cucumber-jvm</artifactId>
1010
<relativePath>../pom.xml</relativePath>
11-
<version>1.0.0.RC7-SNAPSHOT</version>
11+
<version>1.0.0.RC11-SNAPSHOT</version>
1212
</parent>
1313

1414
<artifactId>cucumber-scala</artifactId>

0 commit comments

Comments
 (0)