JBehave
  1. JBehave
  2. JBEHAVE-1069

Paranamer doesn't support test steps with lambda-expressions inside

    Details

    • Type: Bug Bug
    • Status: Open Open
    • Priority: Critical Critical
    • Resolution: Unresolved
    • Affects Version/s: 3.9.3
    • Fix Version/s: None
    • Component/s: Core
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Let's implement simple step with lambda-expression inside:

      import org.jbehave.core.annotations.When;
      import org.jbehave.core.model.ExamplesTable;
      
      import java.util.List;
      import java.util.stream.Collectors;
      
      public class SomeSteps {
          @When("cat eats $species")
          public void somethingHappens(ExamplesTable speciesTable) {
              List<String> species = speciesTable.getRows().stream().map(r -> r.get("Name")).collect(Collectors.toList());
              for (String s : species) {
                  System.out.println("Cat eat " + s);
              }
          }
      }
      

      When JBehave tries to read parameter names following exception occurs:

      java.lang.ArrayIndexOutOfBoundsException: 19562
      	at com.thoughtworks.paranamer.BytecodeReadingParanamer$ClassReader.accept(BytecodeReadingParanamer.java:554)
      	at com.thoughtworks.paranamer.BytecodeReadingParanamer$ClassReader.access$200(BytecodeReadingParanamer.java:337)
      	at com.thoughtworks.paranamer.BytecodeReadingParanamer.lookupParameterNames(BytecodeReadingParanamer.java:102)
      	at com.thoughtworks.paranamer.CachingParanamer.lookupParameterNames(CachingParanamer.java:75)
      	at org.jbehave.core.steps.StepCreator.paranamerParameterNames(StepCreator.java:197)
      	at org.jbehave.core.steps.StepCreator.parameterNames(StepCreator.java:134)
      	at org.jbehave.core.steps.StepCreator.access$900(StepCreator.java:36)
      	at org.jbehave.core.steps.StepCreator$ParametrisedStep.parametriseStep(StepCreator.java:637)
      	at org.jbehave.core.steps.StepCreator$ParametrisedStep.perform(StepCreator.java:592)
      	at org.jbehave.core.embedder.StoryRunner$FineSoFar.run(StoryRunner.java:535)
      	at org.jbehave.core.embedder.StoryRunner.runStepsWhileKeepingState(StoryRunner.java:515)
      	at org.jbehave.core.embedder.StoryRunner.runScenarioSteps(StoryRunner.java:479)
      	at org.jbehave.core.embedder.StoryRunner.runStepsWithLifecycle(StoryRunner.java:445)
      	at org.jbehave.core.embedder.StoryRunner.runCancellable(StoryRunner.java:305)
      	at org.jbehave.core.embedder.StoryRunner.run(StoryRunner.java:220)
      	at org.jbehave.core.embedder.StoryRunner.run(StoryRunner.java:181)
      	at org.jbehave.core.embedder.StoryManager$EnqueuedStory.call(StoryManager.java:235)
      	at org.jbehave.core.embedder.StoryManager$EnqueuedStory.call(StoryManager.java:207)
      	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      	at java.lang.Thread.run(Thread.java:745)
      

      But if I replace lambda expression with anonymous class, all works fine:

          @When("cat eats $species")
          public void somethingHappens(ExamplesTable speciesTable) {
              List<String> species = speciesTable.getRows().stream().map(new Function<Map<String, String>, String>() {
                  @Override
                  public String apply(Map<String, String> row) {
                      return row.get("Name");
                  }
              }).collect(Collectors.toList());
              for (String s : species) {
                  System.out.println("Cat eat " + s);
              }
          }
      

      This bug was also reported early for Thucydides: https://java.net/jira/browse/THUCYDIDES-247

        Activity

        There are no entries against this issue.

          People

          • Assignee:
            Unassigned
            Reporter:
            Nikolay Artamonov
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: