Skip to content

Commit

Permalink
cucumber#154, RunCukesTest.scala uses ScalaBackend.loadGlue which cal…
Browse files Browse the repository at this point in the history
…ls 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
  • Loading branch information
teigen committed Jan 21, 2012
1 parent baca12b commit 4eaf0d4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public <T> T instantiateExactlyOneSubclass(Class<T> parentType, String packagePa
public <T> Collection<? extends T> instantiateSubclasses(Class<T> parentType, String packagePath, Class[] constructorParams, Object[] constructorArgs) {
Collection<T> result = new HashSet<T>();
for (Class<? extends T> clazz : getDescendants(parentType, packagePath)) {
if (Utils.isInstantiable(clazz)) {
if (Utils.isInstantiable(clazz) && Utils.hasConstructor(clazz, constructorParams)) {
result.add(newInstance(constructorParams, constructorArgs, clazz));
}
}
Expand Down
9 changes: 9 additions & 0 deletions core/src/main/java/cucumber/runtime/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ public static <T> List<T> listOf(int size, T obj) {
public static boolean isInstantiable(Class<?> clazz) {
return Modifier.isPublic(clazz.getModifiers()) && !Modifier.isAbstract(clazz.getModifiers());
}

public static boolean hasConstructor(Class<?> clazz, Class[] paramTypes) {
try {
clazz.getConstructor(paramTypes);
return true;
} catch (NoSuchMethodException e) {
return false;
}
}

public static String packagePath(Class clazz) {
return packagePath(packageName(clazz.getName()));
Expand Down
5 changes: 2 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@
<artifactId>cucumber-picocontainer</artifactId>
<version>${project.version}</version>
</dependency>
<!-- Not cooking scala, should not include it in the depends
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-scala</artifactId>
<version>${project.version}</version>
</dependency> -->
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>gherkin</artifactId>
Expand Down Expand Up @@ -254,8 +253,8 @@
<module>rhino</module>
<module>java</module>
<module>clojure</module>
<module>scala</module>

<!--<module>scala</module>-->
<!--<module>openejb</module>-->
</modules>

Expand Down
2 changes: 1 addition & 1 deletion scala/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm</artifactId>
<relativePath>../pom.xml</relativePath>
<version>1.0.0.RC7-SNAPSHOT</version>
<version>1.0.0.RC11-SNAPSHOT</version>
</parent>

<artifactId>cucumber-scala</artifactId>
Expand Down

0 comments on commit 4eaf0d4

Please sign in to comment.