user3723491
user3723491

Reputation: 165

Using sun.reflect package with openjdk11

Is there a way to use sun.reflect in OpenJDK11, by maybe adding something in "--add-exports"? Our code fails since a jide pkg internally uses sun.reflect package and I'm trying to see if there's a way to make it work.

I've already tried with the below but that doesn't help.

"--add-exports jdk.unsupported/sun.reflect=ALL-UNNAMED"

Here's the exception, where the underlying class references sun.reflect.Reflection

java.lang.NoClassDefFoundError: sun/reflect/Reflection

Upvotes: 3

Views: 8276

Answers (3)

berkeerdm
berkeerdm

Reputation: 1

It can be fixed when you update the version of the jars.

Upvotes: 0

Rafal Jastrzebski
Rafal Jastrzebski

Reputation: 1

If you cannot migrate to newer versions, the solution is to make a wrapper around Throwable().getStackTrace()[n].getClass() and put it in WEB-INF/classes folder

This is simple workaround. It works in many cases.

package sun.reflect;
public class Reflection {
        public static Class<?> getCallerClass(int n){
            StackTraceElement[] elements = new Throwable().getStackTrace();
              return elements[n].getClass() ;
            }
}

https://github.com/rafaljot/NoClassDefFoundError-sun-reflect-Reflection

Upvotes: 0

Guest
Guest

Reputation: 11

I had this problem and fixed it by using a newer version of jide. Changing from jide-whatever:3.2.3 to jide-whatever:3.7.6 was enough to make it work in my case.

Upvotes: 1

Related Questions