title: Classloading and Forking exception in Maven Surefire (org.apache.maven.surefire.testset.TestSetFailedException: java.lang.NullPointerException)
body: <p>I am trying to run integration tests on my scim restful server implementation via an embedded jetty server and apache wink REST Client but failing to run the tests. Here is my EmbeddedServerBase class</p>
  
  <pre><code>package org.picketlink.test.scim;
  
  import java.net.URL;
  
  import org.eclipse.jetty.server.Connector;
  import org.eclipse.jetty.server.Server;
  import org.eclipse.jetty.server.bio.SocketConnector;
  import org.eclipse.jetty.servlet.FilterHolder;
  import org.eclipse.jetty.servlet.FilterMapping;
  import org.eclipse.jetty.servlet.ServletHolder;
  import org.eclipse.jetty.webapp.WebAppContext;
  import org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher;
  import org.junit.After;
  import org.junit.Before;
  import org.picketlink.scim.PicketLinkSCIMApplication;
  
  public class EmbeddedWebServerBase {
  protected Server server = null;
  
  @Before
  public void setUp() throws Exception {
      // Start the Jetty embedded container
      server = new Server();
  
      server.setConnectors(getConnectors());
  
      this.establishUserApps();
  
      server.start();
  }
  
  @After
  public void tearDown() throws Exception {
      if (server != null) {
          server.stop();
          try {
              server.destroy();
          } catch (Exception e) {
              //Don't bother
          }
          server = null;
      }
  }
  
  /**
   * Return the connectors that need to be configured on the server. Subclasses can create as many connectors as they want
   *
   * @return
   */
  protected Connector[] getConnectors() {
      Connector connector = new SocketConnector();
      connector.setPort(11080);
      return new Connector[] { connector };
  }
  
  /**
   * Establish the user applications - context, servlets etc
   */
  protected void establishUserApps() {
      ClassLoader tcl = Thread.currentThread().getContextClassLoader();
      if (tcl == null) {
          tcl = getClass().getClassLoader();
      }
  
      final String WEBAPPDIR = "scim";
  
      final String CONTEXTPATH = "/*";
  
      // for localhost:port/admin/index.html and whatever else is in the webapp directory
      final URL warUrl = tcl.getResource(WEBAPPDIR);
      final String warUrlString = warUrl.toExternalForm();
  
      WebAppContext context = createWebApp(CONTEXTPATH, warUrlString);
      context.setClassLoader(getClass().getClassLoader());
      context.setExtraClasspath(warUrlString + "/..");
  
      context.setConfigurationClasses(new String[] { "org.eclipse.jetty.webapp.WebInfConfiguration",
              "org.eclipse.jetty.webapp.WebXmlConfiguration", "org.eclipse.jetty.webapp.MetaInfConfiguration",
              "org.eclipse.jetty.webapp.FragmentConfiguration", "org.eclipse.jetty.plus.webapp.EnvConfiguration",
              //"org.eclipse.jetty.plus.webapp.PlusConfiguration",
              "org.eclipse.jetty.webapp.JettyWebXmlConfiguration", "org.eclipse.jetty.webapp.TagLibConfiguration" });
  
      context.setContextPath("/");
  
      ServletHolder servletHolder = new ServletHolder(new HttpServletDispatcher());
      servletHolder.setInitParameter("javax.ws.rs.Application", PicketLinkSCIMApplication.class.getName());
      context.addServlet(servletHolder, "/*");
  
      server.setHandler(context);
  }
  
  protected FilterMapping createFilterMapping(String pathSpec, FilterHolder filterHolder)      {
      FilterMapping filterMapping = new FilterMapping();
      filterMapping.setPathSpec(pathSpec);
      filterMapping.setFilterName(filterHolder.getName());
      return filterMapping;
  }
  
  protected WebAppContext createWebApp(String contextPath, String warURLString) {
      WebAppContext webapp = new WebAppContext();
      webapp.setContextPath(contextPath);
      webapp.setWar(warURLString);
  
      Thread.currentThread().setContextClassLoader(webapp.getClassLoader());
      return webapp;
  }
  }
  </code></pre>
  
  <p>The exception is most probably thrown at "webapp.getClassLoader()" in Thread.currentThread().setContextClassLoader(webapp.getClassLoader());</p>
  
  <p>Here is a link to the <a href="http://maven.apache.org/surefire/maven-surefire-plugin/examples/class-loading.html" rel="nofollow">Classloading and Forking problems in Maven Surefire</a> </p>
  
  <p>Here is a snippet from CrudTest.java</p>
  
  <pre><code>package org.picketlink.scim.restful.client.test;
  
  import org.junit.Before;
  import org.junit.Ignore;
  import org.junit.Test;
  import org.picketlink.scim.core.entities.ObjectFactory;
  import org.picketlink.scim.restful.client.Client;
  import org.picketlink.scim.restful.client.Tests;
  import org.picketlink.test.scim.EmbeddedWebServerBase;
  
  public class CrudTest extends EmbeddedWebServerBase {
  private Client client = null;
  private ObjectFactory factory = null;
  
  @Before
  public void onBefore() {
      // create a client to send the user/group crud requests
      client = new Client("http://localhost:11080/scim", "matt", "password");
  
      // create an object factory to create the user/group objects
      factory = new ObjectFactory();
  }
  
  @Test
  public void testBasicCrud() {
      // test the create user functionality
      String gid = Tests.createGroupTest(client, factory);
  }
  }
  </code></pre>
  
  <p>Here is the stacktrace</p>
  
  <pre><code>-------------------------------------------------------
  T E S T S
  -------------------------------------------------------
  Running org.picketlink.scim.restful.client.test.CrudTest
  SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
  SLF4J: Defaulting to no-operation (NOP) logger implementation
  SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
  Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.432 sec - in     org.picketlink.scim.restful.client.test.CrudTest
  
  Results :
  
  Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
  
  [INFO] ------------------------------------------------------------------------
  [INFO] BUILD FAILURE
  [INFO] ------------------------------------------------------------------------
  [INFO] Total time: 12.954s
  [INFO] Finished at: Fri Sep 26 00:22:46 IST 2014
  [INFO] Final Memory: 28M/299M
  [INFO] ------------------------------------------------------------------------
  [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.17:test  (default-test) on project picketlink-rest: ExecutionException: java.lang.RuntimeException:  There was an error in the forked process
  [ERROR] org.apache.maven.surefire.testset.TestSetFailedException:  java.lang.NullPointerException
  [ERROR] at org.apache.maven.surefire.common.junit4.JUnit4RunListener.rethrowAnyTestMechanismFailures(JUnit4RunListener.java:206)
  [ERROR] at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:129)
  [ERROR] at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:200)
  [ERROR] at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
  [ERROR] at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
  [ERROR] Caused by: java.lang.NullPointerException
  [ERROR] at org.apache.maven.surefire.report.SmartStackTraceParser.getClass(SmartStackTraceParser.java:67)
  [ERROR] at org.apache.maven.surefire.report.SmartStackTraceParser.&lt;init&gt;(SmartStackTraceParser.java:57)
  [ERROR] at org.apache.maven.surefire.common.junit4.JUnit4StackTraceWriter.smartTrimmedStackTrace(JUnit4StackTraceWriter.java:77)
  [ERROR] at org.apache.maven.surefire.booter.ForkingRunListener.encode(ForkingRunListener.java:328)
  [ERROR] at org.apache.maven.surefire.booter.ForkingRunListener.encode(ForkingRunListener.java:312)
  [ERROR] at org.apache.maven.surefire.booter.ForkingRunListener.toString(ForkingRunListener.java:258)
  [ERROR] at org.apache.maven.surefire.booter.ForkingRunListener.testError(ForkingRunListener.java:132)
  [ERROR] at org.apache.maven.surefire.common.junit4.JUnit4RunListener.testFailure(JUnit4RunListener.java:114)
  [ERROR] at org.junit.runner.notification.RunNotifier$4.notifyListener(RunNotifier.java:100)
  [ERROR] at org.junit.runner.notification.RunNotifier$SafeNotifier.run(RunNotifier.java:41)
  [ERROR] at org.junit.runner.notification.RunNotifier.fireTestFailure(RunNotifier.java:97)
  [ERROR] at org.junit.internal.runners.model.EachTestNotifier.addFailure(EachTestNotifier.java:26)
  [ERROR] at org.junit.internal.runners.model.EachTestNotifier.addMultipleFailureException(EachTestNotifier.java:33)
  [ERROR] at org.junit.internal.runners.model.EachTestNotifier.addFailure(EachTestNotifier.java:24)
  [ERROR] at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:267)
  [ERROR] at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
  [ERROR] at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
  [ERROR] at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
  [ERROR] at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
  [ERROR] at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
  [ERROR] at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
  [ERROR] at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
  [ERROR] at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
  [ERROR] at   org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:264)
  [ERROR] at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
  [ERROR] at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:124)
  [ERROR] ... 3 more
  [ERROR] -&gt; [Help 1]
  [ERROR]
  [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
  [ERROR] Re-run Maven using the -X switch to enable full debug logging.
  [ERROR]
  [ERROR] For more information about the errors and possible solutions, please read the following articles:
  [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
  </code></pre>