jmockit / jmockit1

Advanced Java library for integration testing, mocking, faking, and code coverage
Other
461 stars 239 forks source link

NoClassDefFoundError: org/omg/IOP/IORHelper Jmockit 1.49 and JDK-11 #728

Open yarix opened 2 years ago

yarix commented 2 years ago

Please provide the following information:

any idea how to solve?

FATAL ERROR in native method: processing of -javaagent failed, processJavaStart failed
Exception in thread "main" java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:513)
    at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:525)
Caused by: java.lang.NoClassDefFoundError: org/omg/IOP/IORHelper
    at mockit.internal.startup.MockingBridgeFields.createSyntheticFieldsInJREClassToHoldMockingBridges(MockingBridgeFields.java:32)
    at mockit.internal.startup.Startup.initialize(Startup.java:56)
    at mockit.internal.startup.Startup.premain(Startup.java:48)
    ... 6 more
Caused by: java.lang.ClassNotFoundException: org.omg.IOP.IORHelper
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    ... 9 more
*** java.lang.instrument ASSERTION FAILED ***: "result" with message agent load/premain call failed at src/java.instrument/share/native/libinstrument/JPLISAgent.c line: 422
GitPopcorn commented 1 year ago

same error, does anyone know how to fix it?

Upgrade the version of JMockit will effectively resolve this. And I'm pretty sure you were not using the version 1.49 because there is already no importing for the type IORHelper, this type has been removed from JAVA 11. This is the code of MockingBridgeFields.createSyntheticFieldsInJREClassToHoldMockingBridges() in JMockit 1.22

    static void createSyntheticFieldsInJREClassToHoldMockingBridges(@Nonnull Instrumentation inst) {
        ClassFileTransformer trans = new FieldAdditionTransformer();
        inst.addTransformer(trans);

        try {
            IORHelper.id();
        } finally {
            inst.removeTransformer(trans);
        }

        setMockingBridgeFields();
    }

And this is the code of ClassLoadingBridgeFields.createSyntheticFieldsInJREClassToHoldClassLoadingBridges() in JMockit 1.49

    static void createSyntheticFieldsInJREClassToHoldClassLoadingBridges(@Nonnull Instrumentation instrumentation) {
        FieldAdditionTransformer fieldAdditionTransformer = new FieldAdditionTransformer(instrumentation);
        instrumentation.addTransformer(fieldAdditionTransformer);
        NegativeArraySizeException.class.getName();
        String hostClassName = fieldAdditionTransformer.hostClassName;
        if (hostClassName == null) {
            Provider.class.getName();
            hostClassName = fieldAdditionTransformer.hostClassName;
        }

        ClassLoadingBridge.hostJREClassName = hostClassName;
    }
mayurgithub commented 9 months ago

same error, does anyone know how to fix it?

Upgrade the version of JMockit will effectively resolve this. And I'm pretty sure you were not using the version 1.49 because there is already no importing for the type IORHelper, this type has been removed from JAVA 11. This is the code of MockingBridgeFields.createSyntheticFieldsInJREClassToHoldMockingBridges() in JMockit 1.22

    static void createSyntheticFieldsInJREClassToHoldMockingBridges(@Nonnull Instrumentation inst) {
        ClassFileTransformer trans = new FieldAdditionTransformer();
        inst.addTransformer(trans);

        try {
            IORHelper.id();
        } finally {
            inst.removeTransformer(trans);
        }

        setMockingBridgeFields();
    }

And this is the code of ClassLoadingBridgeFields.createSyntheticFieldsInJREClassToHoldClassLoadingBridges() in JMockit 1.49

    static void createSyntheticFieldsInJREClassToHoldClassLoadingBridges(@Nonnull Instrumentation instrumentation) {
        FieldAdditionTransformer fieldAdditionTransformer = new FieldAdditionTransformer(instrumentation);
        instrumentation.addTransformer(fieldAdditionTransformer);
        NegativeArraySizeException.class.getName();
        String hostClassName = fieldAdditionTransformer.hostClassName;
        if (hostClassName == null) {
            Provider.class.getName();
            hostClassName = fieldAdditionTransformer.hostClassName;
        }

        ClassLoadingBridge.hostJREClassName = hostClassName;
    }

Thanks!! Upgrading worked for me