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

10

38

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)*
Burnish answered 29/8, 2021 at 16:11 Comment(1)
I imagine the following leads to the solution, although I imagine it might be a little difficult for you to understand: #41265766 .Detruncate
K
35

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>
Kennard answered 14/6, 2022 at 11:27 Comment(0)
D
8

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

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

Debussy answered 20/8, 2023 at 19:11 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Calamander
K
7

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/

Konstantin answered 29/8, 2021 at 20:15 Comment(2)
Hi, I am getting the same error. How do you know that this is the cause? What part of that error message tells you that this is the case? I am trying to create a selenium cucumber project in Eclipse and my java version is 17./ How would I know what versions of cucumber, junit etc to use? Thanks.Annorah
Bit hard to explain if you haven't followed the Java lifecycle closely. The tutorial I linked in the answer uses a recent version that works with Java 17.Konstantin
K
7

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

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

Karyolysis answered 3/3, 2023 at 21:0 Comment(2)
Luciano Brum you mean you just uninstalled java 17 and re installed with Java 8 ?Vasty
You can do that but it is not necessary. Using your favorite IDE you can just change the JDK version used by your application. In my case, I forgot to change from java 17 to java 8, this happened because my default environment is set with java 17.Karyolysis
A
1

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.

Apostrophize answered 5/4, 2023 at 11:55 Comment(0)
C
1

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.

Cletuscleve answered 20/10, 2023 at 9:54 Comment(0)
C
1

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

Cletuscleve answered 6/5, 2024 at 7:44 Comment(0)
B
0

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 {}
Bilharziasis answered 21/10, 2021 at 14:1 Comment(0)
A
0

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.

Amby answered 25/1, 2022 at 17:50 Comment(0)
H
0

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.

Hop answered 28/6, 2023 at 7:32 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.