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

Mocking System.nanoTime() cause StackOverflowError #317

Closed
hkalina opened this Issue Aug 6, 2016 · 0 comments

Comments

2 participants
@hkalina

hkalina commented Aug 6, 2016

Affected JMockit version: 1.26 (example works correctly with 1.22 and 1.24)

Mocking of System.nanoTime() fails because using this method in URLClassLoader - mocking of time cause StackOverflowError during classloading. (Mocking of other System methods works ok.)

The same problem occure in version 1.24 if I omit @RunWith(JMockit.class) annotation.

@RunWith(JMockit.class)
public class MyTest {
    @Test
    public void test() {
        System.out.println(System.nanoTime());
        new MockUp<System>() {
            @Mock
            public long nanoTime(){
                return 1234;
            }
        };
        System.out.println(System.nanoTime());
    }
}
*** java.lang.instrument ASSERTION FAILED ***: "!errorOutstanding" with message transform method call failed at JPLISAgent.c line: 844
*** java.lang.instrument ASSERTION FAILED ***: "!errorOutstanding" with message transform method call failed at JPLISAgent.c line: 844

java.lang.StackOverflowError
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:411)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at mockit.internal.mockups.MockMethodBridge.invoke(MockMethodBridge.java:32)
 -> at java.lang.System.nanoTime(System.java)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:444)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at mockit.internal.mockups.MockMethodBridge.invoke(MockMethodBridge.java:32)
 -> at java.lang.System.nanoTime(System.java)
    ...

@rliesenfeld rliesenfeld added the bug label Aug 6, 2016

@rliesenfeld rliesenfeld self-assigned this Aug 6, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment