Skip to content

IndexOutOfBoundException thrown when running Basic Arithmetic example #491

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
restagner opened this issue Mar 22, 2013 · 5 comments
Closed

Comments

@restagner
Copy link

Cucumber-JVM version: 1.1.3
JUnit version: 4.11

I've copied over the Basic Arithmetic java example contained within the cucumber-jvm project to my demo project (i.e., the RpnCalculator.java and RpnCalculatorStepdefs.java classes).

JUnit class

import org.junit.runner.RunWith;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@Cucumber.Options(
        features = { "classpath:features/basic_arithmetic.feature:6"}
        , dryRun = false
        , monochrome = true
        , format = {"pretty", "html:target/results", "json:target/cucumber.json" }
//      , tags = { "@manual" }
        , glue = { "org.stag.simple" })
public class SimpleTest {
}

When I attempt to run the first scenario...

  Background: A Calculator
    Given a calculator I just turned on

  Scenario: Addition
  # Try to change one of the values below to provoke a failure
    When I add 4 and 5
    Then the result is 9

using the mvn clean test command, it produces the following console output

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running org.stag.simple.SimpleTest

Feature: Basic Arithmetic

  Background: A Calculator              # features/basic_arithmetic.feature:3
    Given a calculator I just turned on # RpnCalculatorStepdefs.a_calculator_I_just_turned_on()

  Scenario: Addition   # features/basic_arithmetic.feature:6
    # Try to change one of the values below to provoke a failure
    When I add 4 and 5 # RpnCalculatorStepdefs.adding(int,int)
    Then the result is 9Tests run: 4, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.31 sec <<< FAILURE!

Results :

Tests in error: 
  Feature: Basic Arithmetic: Index: 0, Size: 0

Tests run: 4, Failures: 0, Errors: 1, Skipped: 0

[ERROR] There are test failures.

and the following stack trace

-------------------------------------------------------------------------------
Test set: org.stag.simple.SimpleTest
-------------------------------------------------------------------------------
Tests run: 4, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.31 sec <<< FAILURE!
Feature: Basic Arithmetic  Time elapsed: 0.012 sec  <<< ERROR!
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.RangeCheck(ArrayList.java:547)
    at java.util.ArrayList.remove(ArrayList.java:387)
    at gherkin.formatter.PrettyFormatter.indentedLocation(PrettyFormatter.java:142)
    at gherkin.formatter.PrettyFormatter.printStep(PrettyFormatter.java:255)
    at gherkin.formatter.PrettyFormatter.result(PrettyFormatter.java:199)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at cucumber.runtime.Utils$1.call(Utils.java:44)
    at cucumber.runtime.Timeout.timeout(Timeout.java:12)
    at cucumber.runtime.Utils.invoke(Utils.java:40)
    at cucumber.runtime.RuntimeOptions$2.invoke(RuntimeOptions.java:138)
    at $Proxy11.result(Unknown Source)
    at cucumber.runtime.junit.JUnitReporter.result(JUnitReporter.java:99)
    at cucumber.runtime.Runtime.runStep(Runtime.java:280)
    at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:49)
    at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:43)
    at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:36)
    at cucumber.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:83)
    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:77)
    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:82)
    at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
    at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
    at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
@sishbi
Copy link

sishbi commented Mar 25, 2013

I think this bug is limited to the 'pretty' formatter as I get this issue also for my tests but it goes away if I change to the 'progress' formatter.

@marcenuc
Copy link

marcenuc commented Apr 3, 2013

Same problem here. It is a 1.1.3 regression, because running the same features with cucumber-jvm 1.1.2 works without problem. Only happens with "pretty" formatter.

@rmannibucau
Copy link
Contributor

same issue on trunk,

it happens when there is no statement

@aslakhellesoy
Copy link
Contributor

I think this is a dupe of cucumber/gherkin#252.

@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants