[Bug] [JVM] String index out of range if Step Definition arguments are out of order in Step string

118 views
Skip to first unread message

Yuhau Lin

unread,
Aug 18, 2016, 7:54:34 PM8/18/16
to Cukes
To reproduce:

The following are all included in the attached project.

Step definition class:
public class MyStepDefs {
 
@Given("(?i)^Testing123:(?=.*(arg1))(?=.*(arg2)).*$")
 
public void i_think_this_fails(String arg1, String arg2) {
 
}
}


Feature file:
Feature:

 
Scenario Outline:
   
Given Testing123: arg2 arg1

   
Examples:
     
| lol |
     
|     |
     
|     |



Runner class:
import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(plugin = "pretty")
public class Runner {
}


Maven pom.xml:
  <modelVersion>4.0.0</modelVersion>
  <groupId>hey</groupId>
  <artifactId>sup</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>1.2.4</version>
        <scope>test</scope>
      </dependency>
      <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>1.2.4</version>
        <scope>test</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>
    <dependency>
      <groupId>info.cukes</groupId>
      <artifactId>cucumber-java</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>info.cukes</groupId>
      <artifactId>cucumber-junit</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>


Do this:
mvn test -Dtest=Runner


Here is the stack trace:
java.lang.StringIndexOutOfBoundsException: String index out of range: -9
        at java
.lang.String.substring(String.java:1967)
        at gherkin
.formatter.StepPrinter.writeStep(StepPrinter.java:11)
        at gherkin
.formatter.PrettyFormatter.printStep(PrettyFormatter.java:259)
        at gherkin
.formatter.PrettyFormatter.printSteps(PrettyFormatter.java:130)
        at gherkin
.formatter.PrettyFormatter.replay(PrettyFormatter.java:121)
        at gherkin
.formatter.PrettyFormatter.scenario(PrettyFormatter.java:98)
        at sun
.reflect.GeneratedMethodAccessor16.invoke(Unknown Source)
        at sun
.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java
.lang.reflect.Method.invoke(Method.java:497)
        at cucumber
.runtime.Utils$1.call(Utils.java:37)
        at cucumber
.runtime.Timeout.timeout(Timeout.java:13)
        at cucumber
.runtime.Utils.invoke(Utils.java:31)
        at cucumber
.runtime.RuntimeOptions$1.invoke(RuntimeOptions.java:290)
        at com
.sun.proxy.$Proxy14.scenario(Unknown Source)
        at cucumber
.runtime.junit.JUnitReporter.scenario(JUnitReporter.java:175)
        at gherkin
.formatter.model.Scenario.replay(Scenario.java:18)
        at cucumber
.runtime.model.StepContainer.format(StepContainer.java:31)
        at cucumber
.runtime.model.CucumberScenario.run(CucumberScenario.java:43)
        at cucumber
.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:91)
        at org
.junit.runners.Suite.runChild(Suite.java:127)
        at org
.junit.runners.Suite.runChild(Suite.java:26)
        at org
.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
        at org
.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
        at org
.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
        at org
.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
        at org
.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
        at org
.junit.runners.ParentRunner.run(ParentRunner.java:309)
        at cucumber
.runtime.junit.ExamplesRunner.run(ExamplesRunner.java:59)
        at org
.junit.runners.Suite.runChild(Suite.java:127)
        at org
.junit.runners.Suite.runChild(Suite.java:26)
        at org
.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
        at org
.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
        at org
.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
        at org
.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
        at org
.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
        at org
.junit.runners.ParentRunner.run(ParentRunner.java:309)
        at cucumber
.runtime.junit.ScenarioOutlineRunner.run(ScenarioOutlineRunner.java:53)
        at cucumber
.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:63)
        at cucumber
.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:18)
        at org
.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
        at org
.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
        at org
.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
        at org
.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
        at org
.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
        at org
.junit.runners.ParentRunner.run(ParentRunner.java:309)
        at cucumber
.runtime.junit.FeatureRunner.run(FeatureRunner.java:70)
        at cucumber
.api.junit.Cucumber.runChild(Cucumber.java:93)
        at cucumber
.api.junit.Cucumber.runChild(Cucumber.java:37)
        at org
.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
        at org
.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
        at org
.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
        at org
.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
        at org
.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
        at org
.junit.runners.ParentRunner.run(ParentRunner.java:309)
        at cucumber
.api.junit.Cucumber.run(Cucumber.java:98)
        at org
.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:344)
        at org
.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:269)
        at org
.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:240)
        at org
.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:184)
        at org
.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:286)
        at org
.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:240)
        at org
.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121)

Only happens with pretty formatter plugin and does not happen when run from Eclipse's runner. Root cause is pretty formatter is expecting step definition arguments to be passed into step definition method in the same order that they appear in the step, as demonstrated with above code/project.

Yuhau Lin
CucumberBug.zip
Reply all
Reply to author
Forward
0 new messages