Unable to make field private final java.util.Comparator java.util.TreeMap.comparator accessible: java.base doesn't "opens java.util" to unnamed module

I have created a Cucumber feature file and steps file, then I have clicked "Run configurations" for feature file and I see the following in the console. How can I solve this problem?

*Feature: Login into account
  Existing user should be able to login to account using correct credentials
  
Scenario: Login into account with correct credentials     # C:/Users/MI/Desktop/CucumberFramework/CucumberFramework/src/test/java/CucumberFramework/featureFiles/Login.feature:4
    
Given User navigates to stackoverflow website           # LoginSteps.user_navigates_to_stackoverflow_website()
      java.lang.ExceptionInInitializerError
        at cucumber.deps.com.thoughtworks.xstream.XStream.setupConverters(XStream.java:820)
        at cucumber.deps.com.thoughtworks.xstream.XStream.<init>(XStream.java:574)
        at cucumber.deps.com.thoughtworks.xstream.XStream.<init>(XStream.java:530)
        at cucumber.runtime.xstream.LocalizedXStreams$LocalizedXStream.<init>(LocalizedXStreams.java:50)
        at cucumber.runtime.xstream.LocalizedXStreams.newXStream(LocalizedXStreams.java:37)
        at cucumber.runtime.xstream.LocalizedXStreams.get(LocalizedXStreams.java:29)
        at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37)
        at cucumber.runtime.Runtime.runStep(Runtime.java:300)
        at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)
        at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)
        at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:44)
        at cucumber.runtime.model.CucumberFeature.run(CucumberFeature.java:165)
        at cucumber.runtime.Runtime.run(Runtime.java:122)
        at cucumber.api.cli.Main.run(Main.java:36)
        at cucumber.api.cli.Main.main(Main.java:18)
        at ✽.Given User navigates to stackoverflow website(C:/Users/MI/Desktop/CucumberFramework/CucumberFramework/src/test/java/CucumberFramework/featureFiles/Login.feature:5)
     
 Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.util.Comparator java.util.TreeMap.comparator accessible: module java.base does not "opens java.util" to unnamed module @5afa04c
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:357)
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
        at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:177)
        at java.base/java.lang.reflect.Field.setAccessible(Field.java:171)
        at cucumber.deps.com.thoughtworks.xstream.core.util.Fields.locate(Fields.java:39)
        at cucumber.deps.com.thoughtworks.xstream.converters.collections.TreeMapConverter.<clinit>(TreeMapConverter.java:50)
        at cucumber.deps.com.thoughtworks.xstream.XStream.setupConverters(XStream.java:820)
        at cucumber.deps.com.thoughtworks.xstream.XStream.<init>(XStream.java:574)
        at cucumber.deps.com.thoughtworks.xstream.XStream.<init>(XStream.java:530)
        at cucumber.runtime.xstream.LocalizedXStreams$LocalizedXStream.<init>(LocalizedXStreams.java:50)
        at cucumber.runtime.xstream.LocalizedXStreams.newXStream(LocalizedXStreams.java:37)
        at cucumber.runtime.xstream.LocalizedXStreams.get(LocalizedXStreams.java:29)
        at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37)
        at cucumber.runtime.Runtime.runStep(Runtime.java:300)
        at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)
        at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)
        at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:44)
        at cucumber.runtime.model.CucumberFeature.run(CucumberFeature.java:165)
        at cucumber.runtime.Runtime.run(Runtime.java:122)
        at cucumber.api.cli.Main.run(Main.java:36)
        at cucumber.api.cli.Main.main(Main.java:18)
    
And User clicks on the login button on homepage         # LoginSteps.user_clicks_on_the_login_button_on_homepage()
    
And User enters a valid username                        # LoginSteps.user_enters_a_valid_username()
    
And User enters a valid password                        # LoginSteps.user_enters_a_valid_password()
    
When User clicks on the login button                    # LoginSteps.user_clicks_on_the_login_button()
    
Then User should be taken to the successfull login page # LoginSteps.user_should_be_taken_to_the_successfull_login_page()

Failed scenarios:
C:/Users/MI/Desktop/CucumberFramework/CucumberFramework/src/test/java/CucumberFramework/featureFiles/Login.feature:4 # Scenario: Login into account with correct credentials
1 Scenarios (1 failed)
6 Steps (1 failed, 5 skipped)
0m0,357s

java.lang.ExceptionInInitializerError
    at cucumber.deps.com.thoughtworks.xstream.XStream.setupConverters(XStream.java:820)
    at cucumber.deps.com.thoughtworks.xstream.XStream.<init>(XStream.java:574)
    at cucumber.deps.com.thoughtworks.xstream.XStream.<init>(XStream.java:530)
    at cucumber.runtime.xstream.LocalizedXStreams$LocalizedXStream.<init>(LocalizedXStreams.java:50)
    at cucumber.runtime.xstream.LocalizedXStreams.newXStream(LocalizedXStreams.java:37)
    at cucumber.runtime.xstream.LocalizedXStreams.get(LocalizedXStreams.java:29)
    at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37)
    at cucumber.runtime.Runtime.runStep(Runtime.java:300)
    at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)
    at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)
    at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:44)
    at cucumber.runtime.model.CucumberFeature.run(CucumberFeature.java:165)
    at cucumber.runtime.Runtime.run(Runtime.java:122)
    at cucumber.api.cli.Main.run(Main.java:36)
    at cucumber.api.cli.Main.main(Main.java:18)
    at ✽.Given User navigates to stackoverflow website(C:/Users/MI/Desktop/CucumberFramework/CucumberFramework/src/test/java/CucumberFramework/featureFiles/Login.feature:5)

Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.util.Comparator java.util.TreeMap.comparator accessible: module java.base does not "opens java.util" to unnamed module @5afa04c
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:357)
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
    at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:177)
    at java.base/java.lang.reflect.Field.setAccessible(Field.java:171)
    at cucumber.deps.com.thoughtworks.xstream.core.util.Fields.locate(Fields.java:39)
    at cucumber.deps.com.thoughtworks.xstream.converters.collections.TreeMapConverter.<clinit>(TreeMapConverter.java:50)
    at cucumber.deps.com.thoughtworks.xstream.XStream.setupConverters(XStream.java:820)
    at cucumber.deps.com.thoughtworks.xstream.XStream.<init>(XStream.java:574)
    at cucumber.deps.com.thoughtworks.xstream.XStream.<init>(XStream.java:530)
    at cucumber.runtime.xstream.LocalizedXStreams$LocalizedXStream.<init>(LocalizedXStreams.java:50)
    at cucumber.runtime.xstream.LocalizedXStreams.newXStream(LocalizedXStreams.java:37)
    at cucumber.runtime.xstream.LocalizedXStreams.get(LocalizedXStreams.java:29)
    at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37)
    at cucumber.runtime.Runtime.runStep(Runtime.java:300)
    at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)
    at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)
    at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:44)
    at cucumber.runtime.model.CucumberFeature.run(CucumberFeature.java:165)
    at cucumber.runtime.Runtime.run(Runtime.java:122)
    at cucumber.api.cli.Main.run(Main.java:36)
    at cucumber.api.cli.Main.main(Main.java:18)*

Upvotes: 42

Views: 101443

Answers (10)

Chandan Kumar
Chandan Kumar

Reputation: 21

Go to the Eclipse >> On top menu click Window >> Preferences >> Click on Java >> Installed JREs. If here two or more JRE show, then remove all and select only latest JDK

Regards, Chandan Bhagat

enter image description here

Upvotes: 1

Chandan Kumar
Chandan Kumar

Reputation: 21

You can check the JDK is configure with Eclipse. Check from Eclipse >> Window >> Preferences >> Search Jre >> Click on the Install JRE >> Check JDK showing or not. If not in showing then add JDK.

Upvotes: 1

Enlem Enlem
Enlem Enlem

Reputation: 117

this fixed my issue: update maven-war-plugin to 3.2.3

mvn org.apache.maven.plugins:maven-war-plugin:3.2.3

Upvotes: 11

Santu Yadav
Santu Yadav

Reputation: 1

In my case my sts was pointing to jre instead of jdk. This was ressolved once I deleted jre from build path and pointed to jdk home directory.

Upvotes: 0

Chetan Ahirrao
Chetan Ahirrao

Reputation: 1602

For me, it worked when I changed JRE System library to JDK JRE instead of default JRE.
Right click project-> go to Build Path -> Configure Build Path and ADD Library-> Select path to JDK folder and set it as default.

Upvotes: 1

lubrum
lubrum

Reputation: 444

In my case, I forgot to change java version of my application.

After changing java from version 17 to version 8 fixed the issue.

Upvotes: 8

Asaf Magen
Asaf Magen

Reputation: 1114

I did not have an Cucumber feature installed so the problem in my setup was not related to it. what did help me is updating the maven plugin settings in my pom file as below.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <version>3.3.1</version>
</plugin>
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.8.1</version>
</plugin>

Upvotes: 38

M&#252;ge Sasmaz
M&#252;ge Sasmaz

Reputation: 1

Change the maven dependencies. My application uses the info-cukes for cucumber in pom.xml. I changed them with io-cucumber. it works for me.

Upvotes: 0

Suhas Awale
Suhas Awale

Reputation: 11

I've face the same issue but resolved the issue with following code.

******** Feature file **************

Feature: Application login
Scenario: Login into Application
Given user click on login page
When user enter username password
Then user can see home page

*********** StepDefination file************

package StepDefinations;
import org.junit.runner.RunWith;
@RunWith(io.cucumber.junit.Cucumber.class)
public class StepDefination {
@io.cucumber.java.en.Given("^user click on login page$")
public void user_click_on_login_page() throws Throwable {
// Write code here that turns the phrase above into concrete actions
System.out.println("test 1");
}


@io.cucumber.java.en.When("^user enter username password$")
public void user_enter_username_password() throws Throwable {
// Write code here that turns the phrase above into concrete actions
System.out.println("test 2");
}


@io.cucumber.java.en.Then("^user can see home page$")
public void user_can_see_home_page() throws Throwable {
// Write code here that turns the phrase above into concrete actions
System.out.println("test 3");
}}

********* TestRunner file **************

package cucumber.Options;
import org.junit.runner.RunWith;
@RunWith(io.cucumber.junit.Cucumber.class)
@io.cucumber.junit.CucumberOptions(features="src/test/java/features",` `glue={"StepDefinations"})

public class TestRunner {}

Upvotes: 0

M.P. Korstanje
M.P. Korstanje

Reputation: 12059

Your version of Cucumber is not compatible with your version of Java. Either upgrade Cucumber or downgrade Java.

Because of the Scenario you are testing I am guessing you are following an old tutorial. This one is up to date:

https://cucumber.io/docs/guides/10-minute-tutorial/

Upvotes: 7

Related Questions