0

When trying to run a Maven project (I am using IntelliJ to do the same) by using mvn install in the terminal I get the following error:

[ERROR] com.scopic.javachallenge.controllers.TeamProcessControllerTest.testSample  Time elapsed: 0 s  <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityMapper' defined in file [C:\Users\ronit\Documents\Repos\target\classes\com\scopic\javachallenge\mappers\EntityMapper.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanIn
stantiationException: Failed to instantiate [com.scopic.javachallenge.mappers.EntityMapper]: Constructor threw exception; nested exception is java.lang.reflect.InaccessibleObjectException: Unable to make protected native java.lang.Object java.lang.Object.clone() throws java.lang.CloneNotSupportedException acces
sible: module java.base does not "opens java.lang" to unnamed module @66d1af89
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.scopic.javachallenge.mappers.EntityMapper]: Constructor threw exception; nested exception is java.lang.reflect.InaccessibleObjectException: Unable to make protected native java.lang.Object java.lang.Object.clone() throws
 java.lang.CloneNotSupportedException accessible: module java.base does not "opens java.lang" to unnamed module @66d1af89
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected native java.lang.Object java.lang.Object.clone() throws java.lang.CloneNotSupportedException accessible: module java.base does not "opens java.lang" to unnamed module @66d1af89

The class in question, EntityMapper, looks like this simplified:

public class EntityMapper {

    private final MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();

    private final MapperFacade mapper = mapperFactory.getMapperFacade();

    public EntityMapper() throws Exception {
        // public constructor
    }

}

I have tried multiple solutions from other sites, including using throws NullPointException() in the default constructor and changing the VM options to include --add-opens java.base/java.lang=ALL-UNNAMED when running mvn install. None of these have succeeded. I do not know if there is something I am missing in my code or if I have not set up the environment properly - but what does confuse me is the fact that EntityMapper does not actually seem to be getting called anywhere. How can I go about fixing this?

EDIT: After adding the --add-opens to the pom.xml file, mvn install runs fine. However, the same error now appears for mvn spring-boot:run. How does this get fixed, and why does the pom.xml solution only work for the first command?

Ronit Danti
  • 33
  • 1
  • 9

1 Answers1

1

Try to add '--add-opens java.base/java.lang=ALL-UNNAMED' in your pom.xml. See: https://stackoverflow.com/a/71296829/13774637

Ethan Yin
  • 156
  • 4
  • That worked! Thank you so much. Just going to have to sit and figure out why and how that fixed it. – Ronit Danti Jan 31 '23 at 05:17
  • An update to this if I may - mvn install works now, but when I try running mvn spring-boot:run instead, it brings up the exact same error. Why does the fix work for the first command but not the second one? – Ronit Danti Jan 31 '23 at 05:20
  • @RonitDanti I m facing the same issue. wer you able to fix it? – Vishal Kharde Jun 26 '23 at 17:53
  • @VishalKharde Unfortunately no, it's been quite long since I worked on this but if I remember correctly I had an issue with one of the plugins I was using which had gone out-of-date. – Ronit Danti Jun 28 '23 at 05:15