question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enum conversion not working: IllegalArgumentException: argument type mismatch for step argument

See original GitHub issue

Summary

Regression between 3.0.2 and 2.4.0 breaks converting enum parameters of steps

Expected Behavior

After reverting to 2.4.0:

> Task :cucumber
Feature: Calculations

  Scenario: Divide              # src/test/resources/calculation.feature:2
Doing Division
    When Division is calculated # CalculationStepdefs.splitInfoPfShiftIsSelected(CalculationType)

1 Scenarios (1 passed)
1 Steps (1 passed)

Current Behavior

> Task :cucumber FAILED
Feature: Calculations

  Scenario: Divide              # src/test/resources/calculation.feature:2
    When Division is calculated # CalculationStepdefs.splitInfoPfShiftIsSelected(CalculationType)
      cucumber.runtime.CucumberException: Failed to invoke com.example.CalculationStepdefs.splitInfoPfShiftIsSelected(CalculationType) in file:/home/piotr-kubowicz/temp/bugs/cucumber3/build/classes/java/test/, caused by java.lang.IllegalArgumentException: argument type mismatch                                                                                                                            
        at cucumber.runtime.Utils$1.call(Utils.java:29)                                                                               
        at cucumber.runtime.Timeout.timeout(Timeout.java:16)                                                                          
        at cucumber.runtime.Utils.invoke(Utils.java:20)                                                                               
        at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:48)                                               
        at cucumber.runtime.PickleStepDefinitionMatch.runStep(PickleStepDefinitionMatch.java:50)                                      
        at cucumber.runner.TestStep.executeStep(TestStep.java:55)                                                                     
        at cucumber.runner.TestStep.run(TestStep.java:42)                                                                             
        at cucumber.runner.PickleStepTestStep.run(PickleStepTestStep.java:53)                                                         
        at cucumber.runner.TestCase.run(TestCase.java:47)                                                                             
        at cucumber.runner.Runner.runPickle(Runner.java:44)                                                                           
        at cucumber.runtime.Runtime.runFeature(Runtime.java:120)                                                                      
        at cucumber.runtime.Runtime.run(Runtime.java:106)                                                                             
        at cucumber.api.cli.Main.run(Main.java:35)                                                                                    
        at cucumber.api.cli.Main.main(Main.java:18)                                                                                   
Caused by: java.lang.IllegalArgumentException: argument type mismatch                                                                 
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)                                                                
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)                                              
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)                                      
        at java.lang.reflect.Method.invoke(Method.java:498)                                                                           
        at cucumber.runtime.Utils$1.call(Utils.java:26)                                                                               
        ... 13 more                                                                                                                   

Possible Solution

Steps to Reproduce (for bugs)

src/test/resources/calculation.feature

Feature: Calculations
  Scenario: Divide
    When Division is calculated
package com.example;

import cucumber.api.java.en.When;

public class CalculationStepdefs {

    @When("([\\S]+) is calculated")
    public void splitInfoPfShiftIsSelected(CalculationType calculationType) {
        System.out.println("Doing " + calculationType);
    }
}
package com.example;

public enum CalculationType {
    Multiplication,
    Division
}

build.gradle

plugins { id 'java-library' }

def cucumberVersion = '3.0.2'
dependencies {
    testImplementation "io.cucumber:cucumber-java8:$cucumberVersion"
}

repositories {
    jcenter()
}

task cucumber() {
    dependsOn testClasses
    doLast {
        javaexec {
            main = "cucumber.api.cli.Main"
            classpath = configurations.testRuntimeClasspath + sourceSets.main.output + sourceSets.test.output
            args = ['--plugin', 'pretty', '--glue', 'com.example', 'src/test/resources']
        }
    }
}
build.dependsOn cucumber

Context & Motivation

This blocks me from upgrading to 3.0.2.

Your Environment

Java™ SE Runtime Environment (build 1.8.0_172-b11) Ubuntu 17.10

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:21 (17 by maintainers)

github_iconTop GitHub Comments

1reaction
mpkorstanjecommented, Aug 29, 2018

The commit with the fix has a descendant tagged with a release version. But it was the release of datatable not cucumber expressions. Hence the confusion.

1reaction
grasshopper7commented, Jun 12, 2018

@mlvandijk Thanks for the invite. Signed up.

Read more comments on GitHub >

github_iconTop Results From Across the Web

IllegalArgumentException: argument type mismatch in Hibernate
My first step would be to find out which setter that is (for instance by debugging the application in eclipse, setting an exception...
Read more >
Impex Translator - PK conversion not happening, argument ...
Hi Experts, When I use custom impex translator, automatic conversion to PK is not happening. Please see below two impex statements.
Read more >
How to Handle the Incompatible Types Error in Java - Rollbar
The incompatible types error most often occurs when manual or explicit conversion between types is required, but it can also happen by accident ......
Read more >
ProGuard Manual: Troubleshooting - Guardsquare
Troubleshooting for building Java and Android apps with ProGuard. ... the given class that is an argument type or return type in the...
Read more >
Hibernate ORM 5.2.18.Final User Guide - Red Hat on GitHub
Use Hibernate and report any bugs or issues you find. ... Hibernate supports the mapping of Java enums as basic value types in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found