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.

Enhancement: make Java8 lambda steps reflection portable and use stable javac APIs

See original GitHub issue

See:

  • #912: a JDK upgrade which changed class file layout broke Java8 lambda steps
  • #916: closing over local variables breaks Java8 lambda steps
  • #936: Java 8 Lambda steps don’t support Map or List arguments
    • (may not be fixable using the the existing Constant Pool inspector)

Currently, for Java8 lambda steps to work, the step runner needs to know the declared type of all arguments to the step body (see Java8StepDefinition.getParameterInfos).

The declared type can be any runtime type, including primitives like int, normal classes like String or generic types like List<String>. Users can register converters to allow any type for these step params (see cucumber.runtime.ParameterInfo.convert), including perhaps Object (although that would be a pathological case, I expect it might need special handling by the reflector and it does seem to be allowed).

It does look to me like we could replace the class ConstantPool inspector with a compile-time Compiler Annotation Processor which records the declared generic types. See e.g. http://stackoverflow.com/questions/29922668/get-typeelement-from-generic-typeparameterelement-for-java-annotation-processor

This would mean that cucumber-jvm would be using a public supported javac API, instead of hacking about with trying to interpret the class files internals (which might change again).

We could either require Cucumber java8 users to annotate their Step files to give cucumber-jvm access to edit the source, or we could do a full project lombok and register a compiler plugin for everyone who compiles anything with cucumber-java8 on the classpath and scan for (and fixup) all calls to En.Given etc.

I’ll see if I can get this to work and submit a POC.

This will need careful testing, and possibly deserve a major release version, as it will greatly change how java8 steps are compiled. We’ll need to test different compilers and different build tools (Maven, ant, manual javac) and check that they all execute the CAP correctly. First though, I’ll write a proof of concept to see if this can be made to work at all, and what the code would look like with this new approach.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
RichardBradleycommented, Jul 29, 2017

Love it, great work!

0reactions
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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

New and Enhanced APIs That Take Advantage of Lambda ...
In Java SE 8, new classes have been added and existing classes have been enhanced to take advantage of lambda expressions and streams,...
Read more >
Features - JDK 8 - OpenJDK
Features ; core/libs, 103, Parallel Array Sorting ; 107, Bulk Data Operations for Collections ; 109, Enhance Core Libraries with Lambda ; 112 ......
Read more >
Build a custom Java runtime for AWS Lambda
1. Download the desired Java version and copy the local application code to the Docker environment and build it with Maven: · 2....
Read more >
Hibernate Validator 8.0.0.Final - Jakarta Bean Validation ...
The default metadata source are annotations, with the ability to override and extend the meta-data through the use of XML. The API is...
Read more >
Java 8, 9, 10 and 19 new key features and enhancements
Java 8, 9, 10, 11 and beyond delivering new features to the JDK. JDK 8 had come up with so many new features...
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