orika-mapper/orika

Problems with Java 17

ptahchiev opened this issue ยท 21 comments

So I tried my code with Java 17 and I get this exception:

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 @46d21ee0
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
	at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199)
	at java.base/java.lang.reflect.Method.setAccessible(Method.java:193)
	at ma.glasnost.orika.converter.builtin.CloneableConverter.<init>(CloneableConverter.java:64)
	at ma.glasnost.orika.converter.builtin.CloneableConverter$Builtin.<init>(CloneableConverter.java:221)
	at ma.glasnost.orika.converter.builtin.BuiltinConverters.register(BuiltinConverters.java:135)
	at ma.glasnost.orika.impl.DefaultMapperFactory.build(DefaultMapperFactory.java:1278)
	at io.nemesis.platform.core.mapper.MixinAwareMapperFactory.build(MixinAwareMapperFactory.java:160)
	at ma.glasnost.orika.impl.DefaultMapperFactory.getMapperFacade(DefaultMapperFactory.java:881)

Encountered the same issue, as a workaround you can set the following VM option

--add-opens java.base/java.lang=ALL-UNNAMED

Seems that this will be fixed in the 1.6.0 version. I'm waiting for that to release.

+1 saw this with eclipse adoptium 17.0.1.12-hotspot. Reverted to openjdk11 and all was fine.

Any plans on releasing 1.6.0? We use this library extensively and although the workaround is fine its not ideal.

Hi,
any news here?
People are still waiting for this.

@elaatifi should we consider this project dead?

Hi @oliverlockwood , you can see my comment from #372 . Unfortunately it seems dead to me for quite time. ๐Ÿ˜ž

้‡ๅˆฐๅŒๆ ท็š„้—ฎ้ข˜๏ผŒไฝœไธบไธ€็ง่งฃๅ†ณๆ–นๆณ•๏ผŒๆ‚จๅฏไปฅ่ฎพ็ฝฎไปฅไธ‹ VM ้€‰้กน

--add-opens java.base/java.lang=ALL-UNNAMED

after set this ,not good

I was upgrading an API to Java 17 when I faced exact same issue. In a desperate final attempt I changed the maven version from 3.3.9 to 3.8.5 and the error message changed to the following
"The dependencies of some of the beans in the application context form a cycle:"
I added @lazy annotation at one of the beans and now my API is working absolutely fine.

For those using the Gradle JIB-Plugin, solved it as follows:

container {
	jvmFlags = ['--add-opens=java.base/java.lang=ALL-UNNAMED', '-XX:+UseContainerSupport', '-XX:MaxRAMPercentage=75.0']

So I tried my code with Java 17 and I get this exception:

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 @46d21ee0
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
	at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199)
	at java.base/java.lang.reflect.Method.setAccessible(Method.java:193)
	at ma.glasnost.orika.converter.builtin.CloneableConverter.<init>(CloneableConverter.java:64)
	at ma.glasnost.orika.converter.builtin.CloneableConverter$Builtin.<init>(CloneableConverter.java:221)
	at ma.glasnost.orika.converter.builtin.BuiltinConverters.register(BuiltinConverters.java:135)
	at ma.glasnost.orika.impl.DefaultMapperFactory.build(DefaultMapperFactory.java:1278)
	at io.nemesis.platform.core.mapper.MixinAwareMapperFactory.build(MixinAwareMapperFactory.java:160)
	at ma.glasnost.orika.impl.DefaultMapperFactory.getMapperFacade(DefaultMapperFactory.java:881)

use below in your VM arg
--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED

okay, seems to be dead. one year later, the 1.6.0 is not yet released. I'll go for another mapper-option. schade.

Did you fix the issue? I'm still struggling with this issue... @wolfomat

Hi Team, Any update on new version of orika core which is compatible with JDK17. I am facing same issue.

Does anyone have experience using Orika mapper and GraalVM native image?
Do you need to provide extra metadata for the classes that will be mapped at runtime?

Any updates on the existing issue? We need a mapper that uses reflections as we need run time mapping based on versioning logic of ours. Any new project or libraries that can be used which handles Java 17 and Spring Boot 3.0.6 and is managed actively. Thanks!

Any updates ๏ผŸ๏ผŸ๏ผŸ

Unfortunately, no. I have been following Orika Mapper since the start of 2022. There are no updates rolling out.
For the time being, as a workaround we used the following flag as VM Option
--add-opens java.base/java.lang=ALL-UNNAMED
But we conducted a research and found Mapstruct to be the closest best alternative to Orika. I would suggest everyone to consider migrating to another Mapper.

Hi I'm facing a similar issue using TMC Beans for the Helsinki MOOC in JAVA. How can I get to the VM Option to use the flag?

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 @3191379a

[java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)] [java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)] [java.lang.reflect.Method.checkCanSetAccessible(Method.java:199)]
[java.lang.reflect.Method.setAccessible(Method.java:193)]
org.powermock.reflect.internal.WhiteboxImpl.doGetAllMethods(WhiteboxImpl.java:1499) org.powermock.reflect.internal.WhiteboxImpl.getAllMethods(WhiteboxImpl.java:1473) org.powermock.reflect.internal.WhiteboxImpl.findMethodOrThrowException(WhiteboxImpl.java:853) org.powermock.reflect.internal.WhiteboxImpl.doInvokeMethod(WhiteboxImpl.java:813) org.powermock.reflect.internal.WhiteboxImpl.invokeMethod(WhiteboxImpl.java:681) org.powermock.reflect.Whitebox.invokeMethod(Whitebox.java:401) org.powermock.classloading.AbstractClassloaderExecutor.getResult(AbstractClassloaderExecutor.java:76) org.powermock.classloading.AbstractClassloaderExecutor.invokeWithClassLoader(AbstractClassloaderExecutor.java:64) org.powermock.classloading.AbstractClassloaderExecutor.executeWithClassLoader(AbstractClassloaderExecutor.java:56) org.powermock.classloading.SingleClassloaderExecutor.execute(SingleClassloaderExecutor.java:33) org.powermock.classloading.AbstractClassloaderExecutor.execute(AbstractClassloaderExecutor.java:40) org.powermock.modules.junit4.rule.PowerMockStatement.evaluate(PowerMockRule.java:75) org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) org.junit.runners.ParentRunner.run(ParentRunner.java:309) fi.helsinki.cs.tmc.testrunner.TestRunner$TestingRunnable.runTestCase(TestRunner.java:134) fi.helsinki.cs.tmc.testrunner.TestRunner$TestingRunnable.doRun(TestRunner.java:89) fi.helsinki.cs.tmc.testrunner.TestRunner$TestingRunnable.run(TestRunner.java:70) java.lang.Thread.run(Thread.java:833)

Hello

We are using a workaround since last year in order to migrate on jdk17 without --add-opens, this allow the depreciation of Orika without rushing because of jdk17, off course "use it with caution"

The workaround is :

  • switch from the default JavassistCompilerStrategy to EclipseJdtCompilerStrategy
  • disable the default builtin converters
  • add only jdk17 ready converters, and rewrite if not compatible

snippets :

        <dependency>
            <groupId>ma.glasnost.orika</groupId>
            <artifactId>orika-eclipse-tools</artifactId>
            <version>1.5.4</version>
        </dependency>
@Deprecated(forRemoval = true)
public class BidouilleOrikaMapperFactory {

    public static MapperFactory defaultMapperFactory() {
        return new DefaultMapperFactory.Builder()
                .useBuiltinConverters(false)
                .converterFactory(new BidouilleOrikaConverterFactory())
                .compilerStrategy(new BidouilleOrikaCompilerStrategy())
                .build();
    }
}
@Deprecated(forRemoval = true)
public class BidouilleOrikaCompilerStrategy extends EclipseJdtCompilerStrategy {

    @Override
    protected void writeSourceFile(String sourceText, String packageName, String className) throws IOException {

    }
}

see https://github.com/orika-mapper/orika/blob/master/core/src/main/java/ma/glasnost/orika/converter/builtin/BuiltinConverters.java#L77
do not use makeSimpleConverter and rewrite them without reflection if needed (Date is on of them) .

@Deprecated(forRemoval = true)
public class BidouilleOrikaConverterFactory extends DefaultConverterFactory {
    public BidouilleOrikaConverterFactory() {
        super();
        this.registerConverter(new CopyByReferenceConverter());

        this.registerConverter(new EnumConverter());

        /*
         * Register to/from string converters
         */
        this.registerConverter(new FromStringConverter());
        this.registerConverter(new ToStringConverter());

        /*
         * Register common date/time converters
         */
        this.registerConverter(new DateAndTimeConverters.DateToXmlGregorianCalendarConverter());
        this.registerConverter(new DateAndTimeConverters.DateToTimeConverter());
        this.registerConverter(new DateAndTimeConverters.CalendarToXmlGregorianCalendarConverter());
        this.registerConverter(new DateAndTimeConverters.XmlGregorianCalendarToTimestampConverter());
        this.registerConverter(new DateAndTimeConverters.XmlGregorianCalendarToSqlDateConverter());
        this.registerConverter(new DateAndTimeConverters.XmlGregorianCalendarToTimeConverter());
        this.registerConverter(new DateAndTimeConverters.LongToXmlGregorianCalendarConverter());

        this.registerConverter(new DateAndTimeConverters.DateToCalendarConverter());
        this.registerConverter(new DateAndTimeConverters.CalendarToTimeConverter());
        this.registerConverter(new DateAndTimeConverters.CalendarToSqlDateConverter());
        this.registerConverter(new DateAndTimeConverters.LongToCalendarConverter());
        this.registerConverter(new DateAndTimeConverters.TimestampToCalendarConverter());

        this.registerConverter(new DateAndTimeConverters.DateToSqlDateConverter());
        this.registerConverter(new DateAndTimeConverters.LongToSqlDateConverter());
        this.registerConverter(new DateAndTimeConverters.TimeToSqlDateConverter());
        this.registerConverter(new DateAndTimeConverters.TimestampToSqlDateConverter());

        this.registerConverter(new DateAndTimeConverters.LongToTimeConverter());
        this.registerConverter(new DateAndTimeConverters.TimestampToTimeConverter());

        this.registerConverter(new DateAndTimeConverters.LongToTimestampConverter());
        this.registerConverter(new DateAndTimeConverters.DateToTimestampConverter());

        this.registerConverter(new DateAndTimeConverters.LongToDateConverter());

        /*
         * Register numeric type converter
         */
        this.registerConverter(new NumericConverters.BigDecimalToDoubleConverter());
        this.registerConverter(new NumericConverters.BigDecimalToFloatConverter());
        this.registerConverter(new NumericConverters.BigIntegerToIntegerConverter(false));
        this.registerConverter(new NumericConverters.BigIntegerToLongConverter(false));

        this.registerConverter(new NumericConverters.IntegerToShortConverter(false));
        this.registerConverter(new NumericConverters.LongToIntegerConverter(false));
        this.registerConverter(new NumericConverters.LongToShortConverter(false));

        this.registerConverter(new NumericConverters.FloatToShortConverter(false));
        this.registerConverter(new NumericConverters.FloatToIntegerConverter(false));
        this.registerConverter(new NumericConverters.FloatToLongConverter(false));

        this.registerConverter(new NumericConverters.DoubleToShortConverter(false));
        this.registerConverter(new NumericConverters.DoubleToIntegerConverter(false));
        this.registerConverter(new NumericConverters.DoubleToLongConverter(false));
        /*
         * Register converter to instantiate by using a constructor on the
         * destination which takes the source as argument
         */
        this.registerConverter(new ConstructorConverter());
    }
}

Hello All, Any updates for a new Orika release?