Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6814201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:39:40+00:00 2026-05-26T20:39:40+00:00

Using Eclipse 3.6.1 Java 1.6.0_26 JMockit 0.999.10 UPDATE: I was able to create a

  • 0

Using Eclipse 3.6.1
Java 1.6.0_26
JMockit 0.999.10

UPDATE: I was able to create a SSCCE, which I am posting below:

UPDATE2: Added DaemonHelper. Additionally, if I remove DaemonHelper from the constructor, I get a ClassCircularityError instead. Related?

I’m trying to do a partial mock of a class, while mocking several dependencies of the class, when I get an NPE from the Class loader. The NPE call stack is show below

I have a Daemon Class like so:

public class Daemon extends DaemonParent {

public Daemon(ConfigParent config, DaemonHelper helper) {
    super(config, helper);
}

@Override
public void execute() {
    log("Starting");
    if (config.test()) {
        log("Testing");
    }

    log("Ending");  
}
}

The Daemon has a Parent like so:

public abstract class DaemonParent extends Thread {

protected ConfigParent config;
protected DaemonHelper helper;

public DaemonParent(ConfigParent config, DaemonHelper helper) {
    this.config = config;
    this.helper = helper;
}


public abstract void execute();

public void log(String s) {
    System.out.println(s);
}
}

There is a helper class like :

public class DaemonHelper extends Thread {

}

The Config looks like :

public class ConfigParent {

protected ConfigHelper helper;

public ConfigParent(ConfigHelper helper) {
    this.helper = helper;
}

public boolean test() {
    return false;
}
}

The Config Parent looks like :

public class ConfigParent implements Serializable {

protected ConfigHelper helper;

public ConfigParent(ConfigHelper helper) {
    this.helper = helper;
}

public boolean test() {
    return false;
}
}

And the Test looks like :

public class DaemonTest {

@Test
public void testExecute(final ConfigHelper ch, final DaemonHelper dh) {
    final Config c = new Config(ch);
    final Daemon d = new Daemon(c, dh);

    new NonStrictExpectations(d) {
        {

        }
    };

    d.execute();

    new Verifications() {{
        d.log("Starting");
        d.log("Ending");
    }};
}
}

When I try to run this test, I get the following error. Note this error only pops up when the DaemonParent and Daemon Helper have java.lang.Thread as a superclass:

java.lang.NullPointerException
at java.lang.Thread.interrupted(Unknown Source)
at sun.misc.Resource.getBytes(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.junit.internal.runners.model.EachTestNotifier.addFailure(EachTestNotifier.java:23)
at org.junit.runners.ParentRunner.run(ParentRunner.java:242)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

I tried commenting out the NonStrictExpectations block and the Verifications block, and I get the same error.

The NPE is thrown from a call to currentThread()… which I have no Idea how it could fail.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:39:40+00:00Added an answer on May 26, 2026 at 8:39 pm

    It turns out the problem that that the root superclass of Daemon is java.lang.Thread, which caused JMockit to have trouble. The solution was static partial mocking of the methods required by the test.

    public class DaemonTest {
    
    @Test
    public void testExecute(final ConfigHelper ch, final DaemonHelper dh) {
    
    new NonStrictExpectations(d) {
        @Mocked({"log"}
        Daemon d;
        @Mocked({"()"})
        DaemonHelper dh;
        {
    
        }
    };
    
    
    final Config c = new Config(ch);
    final Daemon d = new Daemon(c, dh);
    d.execute();
    
    new Verifications() {{
        d.log("Starting");
        d.log("Ending");
    }};
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I'm using Java jdk 1.6.0_26 for my eclipse based application. As now Java
I'm using eclipse on a windows 7 x64 to create a new Java Application.
I'm using Eclipse for Java development. All my sources compile fine and the resulting
At present I am using eclipse for JAVA project. I always wanted to use
I've been somewhat spoiled using Eclipse and java. I started using vim to do
As an experiment we want to build our products using the Eclipse java compiler
Forgive my ignorance - still learning here. I am using Eclipse Ganymede (Java 1.5)
I have web application written in java using Eclipse. It has just one servlet
I have recently created a web project in Java using eclipse. I have a
Using Eclipse I want to view the source code for a core Java class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.