Mocking of JavaFX Properties failed with java.lang.NoClassDefFoundError: mockit/internal/expectations/RecordAndReplayExecution #246

lauritziu opened this Issue Jan 5, 2016 · 5 comments


None yet

3 participants


I have the following simple test code:

import org.junit.Test;

import mockit.Mocked;
import mockit.NonStrictExpectations;
import mockit.Verifications;

public class JMockitPropertiesTest {
    private Model testModel;

    public void testProperties() {
        new NonStrictExpectations() {{
            testModel.loadingProperty(); result = new SimpleBooleanProperty(false);

        testModel.loadingProperty().bind(new SimpleBooleanProperty(true));

        new Verifications() {{
            testModel.loadingProperty(); times = 1;

    public class Model {

        private BooleanProperty loadingProperty;

        public BooleanProperty loadingProperty() {
            return loadingProperty;

If the test is executed the following exception occurs:

/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/bin/java -ea -Didea.launcher.port=7535 "-Didea.launcher.bin.path=/Applications/development/IntelliJ IDEA" -Didea.junit.sm_runner -Dfile.encoding=UTF-8 -classpath "/Applications/development/IntelliJ IDEA IDEA" com.intellij.rt.execution.application.AppMain com.intellij.rt.execution.junit.JUnitStarter -ideVersion5,testProperties
objc[8949]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.

java.lang.NoClassDefFoundError: mockit/internal/expectations/RecordAndReplayExecution

    at com.sun.javafx.binding.ExpressionHelper.addListener(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.lang.reflect.Method.invoke(
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(
    at com.intellij.rt.execution.junit.JUnitStarter.main(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.lang.reflect.Method.invoke(
    at com.intellij.rt.execution.application.AppMain.main(
Caused by: java.lang.ClassNotFoundException: mockit.internal.expectations.RecordAndReplayExecution
    at java.lang.ClassLoader.loadClass(
    at java.lang.ClassLoader.loadClass(
    ... 12 more

What can be wrong? The mentioned class is in the classpath, because other tests went well. Is there a special problem with JavaFX properties?
@rliesenfeld rliesenfeld added the bug label Jan 6, 2016
@rliesenfeld rliesenfeld self-assigned this Jan 6, 2016

I am having the same issue with release 1.21 of jmockit. I get NoClassDefFoundErrors randomly on classes that are clearly in scope (they exist in the project itself). At first I thought it was related to classes I'm mocking, but it appears to be able to happen to any class. But it's definitely random. Works fine on my box, but not on the build machine. I haven't tracked down what the difference is. I'm reverting to jmockit 1.20, which has not given me this issue.

@lauritziu Version 1.20 does not give me this problem. I'd be interested in your results of trying 1.20.


For me, the problem is reproducible with JMockit 1.20 (and should be with any older version as well).


That's the same for me. The first time it occurred with 1.20. I hoped, that 1.21 have fixed it. I didn't. My impression is, that happens not randomly. @aelmhorst if you execute the code above the error just happen randomly? That's strange.

My environment:
Mac OS El Capitain
Java 1.8.0_60


Unfortunately, this very cool framework is not usable for me at the moment. That's sad because I would like to promote it in my company.


I've been battling with this issue, still with 1.20. My building is working now, and it may be fixed. Time will tell. Here's what I've learned:

I was able to initially get the build to start running again as follows


However, I am using Jacoco for code coverage and setting JMockit as the java agent for Surefire means that Jacoco wasn't running.

Finally what I did was to ensure that JMockit was specified prior to junit in the POM. That seemed to clear up my builds for today. Hopefully that fixes it. There seem to be a number of places where specifying JMockit before Junit is recommended, but according to the documentation that's unnecessary if using the @RunWith( JMockit.class) annotation, which I'm doing on the classes that were failing. However, it has cleared up my issues with builds for today.

@rliesenfeld rliesenfeld added a commit that closed this issue Jan 22, 2016
@rliesenfeld rliesenfeld Fixed incorrect redefinition of classes from Java's extension class l…
…oader, which can't directly access code from the application class loader; closes #246.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment