Cactus
  1. Cactus
  2. CACTUS-74

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

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.5-rc1
    • Fix Version/s: None
    • Component/s: Framework
    • Labels:
      None
    • Environment:
      Operating System: Other
      Platform: PC

      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

        Activity

        Luiz-Otavio Zorzella created issue -
        Serge Knystautas made changes -
        Field Original Value New Value
        issue.field.bugzillaimportkey 24842 15851
        Vincent Massol made changes -
        Fix Version/s 1.7 [ 10693 ]
        Vincent Massol made changes -
        Priority Major [ 3 ]
        Vincent Massol made changes -
        Assignee Cactus Developers Mailing List [ cactus-dev@jakarta.apache.org ]
        Vincent Massol made changes -
        Fix Version/s 1.7 [ 10693 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Luiz-Otavio Zorzella
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:

              Development