Uploaded image for project: 'Cactus'
  1. Cactus
  2. CACTUS-74

java.lang.NullPointerException in first test -- thread synchronization prob?

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.5-rc1
    • None
    • Framework
    • None
    • Operating System: Other
      Platform: PC
    • 24842

    Description

      I've written a fairly simple test case to test a servlet of mine. I log in, as
      required, and do a "doGet":

      public void testOne () throws javax.servlet.ServletException

      { ShowLinks servlet = new ShowLinks (); servlet.init (config); UserValue user = LFGetter.findUserByUsername("user"); Login.login (request, user); servlet.doGet (request, response); }

      This is the only test case in my Cactus suite. Right after deploying it to my
      jboss (jboss-3.2.2), and testing over the browser (with ServletTestRunner), I
      found out that Cactus reports a failure in this test. If I hit "reload" on the
      browser it reports success (and keeps on reporting sucess from then on). If I
      redeploy the EAR file, the same happens: the first time failure, afterwards,
      success. The failure happens with a Cactus NullPointerException (the Exception
      is at the framework itself, not in my servlet), which I narrowed down to this
      line in the method doGetResults():

      writer.write(result.toXml());

      The reason for the exception is that "result" is null. "result" is populated
      right before that with this line:

      WebTestResult result = (WebTestResult) (this.webImplicitObjects
      .getServletContext().getAttribute(TEST_RESULTS));

      I've also figured that it is set in the servletContext by this line in doTest():

      this.webImplicitObjects.getServletContext()
      .setAttribute(TEST_RESULTS, result);

      That comes right after the servlet itself is excecuted, from the line:

      testInstance.runBare();

      After more debugging, I figured out the this "runBare" will open a secondary
      thread, which will execute the "doGetResults()", while the "current thread" will
      be the one that continues the execution of "doTest()".

      ***************************************

      WHAT I THINK:

      The way I see it, the second thread should wait for the first one to set
      "TEST_RESULTS" before it executes "doGetResults()". And I think the reason it
      succeeds from the second test onwards is that this is cached from one run to the
      next.

      Please let me know if you need more information.

      Zorzella

      Attachments

        Activity

          People

            Unassigned Unassigned
            z0084@zorzella.com Luiz-Otavio Zorzella
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: