cucumber/cucumber-jvm — Issue #133: Exceptions being swallowed if reported in a Hook
Author: dkowis
Created: 2012-01-11 22:26:03+00:00
State: open

```
[java] Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
[java] at java.util.ArrayList.RangeCheck(ArrayList.java:547)
[java] at java.util.ArrayList.remove(ArrayList.java:387)
[java] at gherkin.formatter.PrettyFormatter.printStep(PrettyFormatter.java:166)
[java] at gherkin.formatter.PrettyFormatter.result(PrettyFormatter.java:159)
[java] at cucumber.runtime.RuntimeWorld.runHookIfTagsMatch(RuntimeWorld.java:77)
[java] at cucumber.runtime.RuntimeWorld.runHooks(RuntimeWorld.java:59)
[java] at cucumber.runtime.RuntimeWorld.runAfterHooksAndDisposeBackendWorlds(RuntimeWorld.java:43)
[java] at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:39)
[java] at cucumber.runtime.model.CucumberScenarioOutline.run(CucumberScenarioOutline.java:37)
[java] at cucumber.runtime.Runtime.run(Runtime.java:75)
[java] at cucumber.runtime.Runtime.run(Runtime.java:67)
[java] at cucumber.cli.Main.run(Main.java:78)
[java] at cucumber.cli.Main.main(MERROR HAPPENED, and then it nuked the exception stack!
[java] EXCEPTION:
[java] org.jruby.exceptions.RaiseException: (NoMethodError) undefined method `failed?' for nil:NilClass
[java] at #.(root)(com/rackspace/incident/features/ruby/step_definitions/env.rb:33)
[java] at org.jruby.RubyKernel.instance_exec(org/jruby/RubyKernel.java:2079)
[java] ain.java:64)ber::Runtime::JRuby::HookDefinition.execute(/cucumber/runtime/jruby/dsl.rb:60)
```

So in that stack trace there's a bit of code that I added to the RuntimeWorld at line 69 to print the stack trace of the Throwable before it's handed off to the result, because that's the last place in the main stack trace about the Index Out of Bounds Exception.

The cause is a undefined method "failed?" in the After Hook being executed (in Jruby, because somehow the ScenarioResult object isn't being set, but that's a different issue.) So when the reporter gets ahold of this, and tries to output the error, it cannot, because there are no more steps for it to report on, and so it runs over the Array.

This was while running the Jruby CLI feature executor.