8000 Class not found error when using Objenesis in a Java 9 module · Issue #160 · easymock/objenesis · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Class not found error when using Objenesis in a Java 9 module #160

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

Closed
armandino opened this issue Dec 21, 2022 · 3 comments
Closed

Class not found error when using Objenesis in a Java 9 module #160

armandino opened this issue Dec 21, 2022 · 3 comments
Assignees
Milestone

Comments

@armandino
Copy link

This issue came up while investigating jqno/equalsverifier#746.

To summarise, using Objenesis in a Java 9 module results in ClassNotFoundException: sun.reflect.ReflectionFactory

Reproducible sample: https://github.com/armandino/objenesis-java9-module-bug

@tfbroner
Copy link
tfbroner commented Dec 28, 2023

I get the same error in my application, using Java 11:

org.objenesis.ObjenesisException: java.lang.ClassNotFoundException: sun.reflect.ReflectionFactory

Any fixes?

Here's the stack:
Caused by: org.objenesis.ObjenesisException: java.lang.ClassNotFoundException: sun.reflect.ReflectionFactory from [Module "app-deployable.war" from Service Module Loader] app-deployable.war//org.objenesis.instantiator.sun.SunReflectionFactoryHelper.getReflectionFactoryClass(SunReflectionFactoryHelper.java:63) app-deployable.war//org.objenesis.instantiator.sun.SunReflectionFactoryHelper.newConstructorForSerialization(SunReflectionFactoryHelper.java:37) app-deployable.war//org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.<init>(SunReflectionFactoryInstantiator.java:41) app-deployable.war//org.objenesis.strategy.StdInstantiatorStrategy.newInstantiatorOf(StdInstantiatorStrategy.java:68) app-deployable.war//com.esotericsoftware.kryo.Kryo$DefaultInstantiatorStrategy.newInstantiatorOf(Kryo.java:1323) app-deployable.war//com.esotericsoftware.kryo.Kryo.newInstantiator(Kryo.java:1127) app-deployable.war//com.esotericsoftware.kryo.Kryo.newInstance(Kryo.java:1136) app-deployable.war//com.esotericsoftware.kryo.serializers.FieldSerializer.createCopy(FieldSerializer.java:671) app-deployable.war//com.esotericsoftware.kryo.serializers.FieldSerializer.copy(FieldSerializer.java:675) app-deployable.war//com.esotericsoftware.kryo.Kryo.copy(Kryo.java:914) app-deployable.war//com.esotericsoftware.kryo.serializers.UnsafeCacheFields$UnsafeObjectField.copy(UnsafeCacheFields.java:313)

@henri-tremblay henri-tremblay self-assigned this May 6, 2024
@henri-tremblay henri-tremblay added this to the 3.4 milestone May 6, 2024
@henri-tremblay
Copy link
8000
Contributor

I think this was fixed by adding <Dependencies>jdk.unsupported</Dependencies>

@jqno
Copy link
jqno commented May 7, 2024

Unfortunately, I'm still seeing the error.

Here's how I reproduce:

Person.java:

package org.example.domain;

import org.objenesis.*;

public class Person {
    public static void main(String[] args) {
        Objenesis objenesis = new ObjenesisStd();
        objenesis.getInstantiatorOf(Person.class);
    }
}

module-info.java:

module user {
    requires org.objenesis;
    opens org.example.domain;
}

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.example</groupId>
    <artifactId>objenesis-issue-160</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
    </properties>


    <dependencies>
        <dependency>
            <groupId>org.objenesis</groupId>
            <artifactId>objenesis</artifactId>
            <version>3.4</version>
        </dependency>
    </dependencies>
</project>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
0