-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot close over local variables #916
Comments
Interesting. Would you be able to send a pull request with your proposed fix? |
Sure thing, please see above. |
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. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Java8StepDefinition
and more specificallyConstantPoolTypeIntrospector
confuses closed variables with arguments to the accept function. This has the consequence that you are unable to close over local variables.For example, if you define something like
, the lambda closes over the
prefix
variable. Subsequently, theConstantPoolTypeIntrospector
will read out atypeString
not of the expected()V
, but of(Ljava/lang/String;)V
.Java8StepDefinition
will therefore gettypeArguments
ofType[]{ String.class }
. It will then proceed looking for a method called accept with a singleObject
argument, which will fail (it treats all arguments as Object arguments, disregarding the specific type). In other words, it "thinks" that the lamda looks as follows:, even though
prefix
is implicitly passed. I believe this could be solved by simply callingclazz.getDeclaredMethod("accept")
, instead of looking in the constant pool, which evidently exposes implicit dependencies as well as explicit ones.This problem is not present if you close over fields in the
Steps
class.The exception you get when this happens is:
I'm using cucumber 1.2.4
The text was updated successfully, but these errors were encountered: