jmockit1 icon indicating copy to clipboard operation
jmockit1 copied to clipboard

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

Open yarix opened this issue 2 years ago • 2 comments

Please provide the following information:

  • Version of JMockit that was used: 1.49

  • Description of the problem or enhancement request: while upgrading existing code from Java 8, Jmockit 1.22 to Java 11 and jmockit 1.49 - i get the following when running the test from intellij (...yes - with -javaagent:/root/.m2/repository/org/jmockit/jmockit/1.49/jmockit-1.49.jar)

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
  • Check the following:
  • [x] If a defect or unexpected result, JMockit project members should be able to reproduce it. For that, include an example test (perhaps accompanied by a Maven/Gradle build script) which can be executed without changes and reproduces the failure.

  • [ ] If an enhancement or new feature request, it should be justified by an example test demonstrating the validity and usefulness of the desired enhancement or new feature.

  • [ ] The issue does not fall outside the scope of the project (for example, attempting to use JMockit APIs from Groovy or Scala code, or with an Android runtime).

  • [x] The JDK where the problem occurs is a final release, not a development build.

yarix avatar Jun 14 '22 13:06 yarix

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;
    }

GitPopcorn avatar Mar 10 '23 08:03 GitPopcorn

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

mayurgithub avatar Dec 15 '23 18:12 mayurgithub