Skip to content

[Java8] Show error message when used on Java 12+ #1902

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

Merged
merged 1 commit into from
Feb 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions java8/src/main/java/io/cucumber/java8/AbstractGlueDefinition.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.cucumber.java8;

import io.cucumber.core.backend.ScenarioScoped;
import net.jodah.typetools.TypeResolver;

import java.lang.reflect.Method;
import java.util.ArrayList;
Expand Down Expand Up @@ -42,4 +43,18 @@ private Method getAcceptMethod(Class<?> bodyClass) {
}
return acceptMethods.get(0);
}

Class<?>[] resolveRawArguments(Class<?> bodyClass, Class<?> body) {
Class<?>[] rawArguments = TypeResolver.resolveRawArguments(bodyClass, body);
for (Class<?> aClass : rawArguments) {
if (TypeResolver.Unknown.class.equals(aClass)) {
throw new IllegalStateException("" +
"Could resolve the return type of the lambda at " + location.getFileName() + ":" + location.getLineNumber() + "\n" +
"This version of cucumber-java8 is not compatible with Java 12+\n" +
"See: https://github.com/cucumber/cucumber-jvm/issues/1817"
);
}
}
return rawArguments;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

import io.cucumber.core.backend.DataTableTypeDefinition;
import io.cucumber.datatable.DataTableType;
import net.jodah.typetools.TypeResolver;

final class Java8DataTableCellDefinition extends AbstractDatatableElementTransformerDefinition implements DataTableTypeDefinition {

private final DataTableType dataTableType;

Java8DataTableCellDefinition(String[] emptyPatterns, DataTableCellDefinitionBody<?> body) {
super(body, new Exception().getStackTrace()[3], emptyPatterns);
Class<?> returnType = TypeResolver.resolveRawArguments(DataTableCellDefinitionBody.class, body.getClass())[0];
Class<?> returnType = resolveRawArguments(DataTableCellDefinitionBody.class, body.getClass())[0];
this.dataTableType = new DataTableType(
returnType,
(String cell) -> execute(replaceEmptyPatternsWithEmptyString(cell))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import io.cucumber.datatable.DataTable;
import io.cucumber.datatable.DataTableType;

import static net.jodah.typetools.TypeResolver.resolveRawArguments;

final class Java8DataTableDefinition extends AbstractDatatableElementTransformerDefinition implements DataTableTypeDefinition {

private final DataTableType dataTableType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

import java.util.Map;

import static net.jodah.typetools.TypeResolver.resolveRawArguments;

final class Java8DataTableEntryDefinition extends AbstractDatatableElementTransformerDefinition implements DataTableTypeDefinition {

private final DataTableType dataTableType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

import java.util.List;

import static net.jodah.typetools.TypeResolver.resolveRawArguments;

final class Java8DataTableRowDefinition extends AbstractDatatableElementTransformerDefinition implements DataTableTypeDefinition {

private final DataTableType dataTableType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import io.cucumber.core.exception.CucumberException;
import io.cucumber.docstring.DocStringType;

import static net.jodah.typetools.TypeResolver.resolveRawArguments;

final class Java8DocStringTypeDefinition extends AbstractGlueDefinition implements DocStringTypeDefinition {

private final DocStringType docStringType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toList;
import static net.jodah.typetools.TypeResolver.resolveRawArguments;

final class Java8StepDefinition extends AbstractGlueDefinition implements StepDefinition {

Expand Down
3 changes: 0 additions & 3 deletions java8/src/main/java/io/cucumber/java8/LambdaTypeResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ public Type resolve() {
}

public Type getType() {
if (net.jodah.typetools.TypeResolver.Unknown.class.equals(type)) {
return Object.class;
}
return type;
}

Expand Down