0 Replies Latest reply on Mar 13, 2007 5:18 PM by bytor99999

    FacesRequest masks the root cause of an Exception

      I was going to make a Jira entry about it, but figured it is best to post in the forums first. Especially when doing a little research, it looks like this might be happening at the EL apis level.

      Here is what is happening

      SUMMARY: Exception thrown in FacesRequest in SeamTest masks the root cause of the Exception


      ENVIRONMENT: Windows XP. build and running of tests through Maven2.


      DETAILS:
      In running a SeamTest that throws an exception in a FacesRequest masks the real cause of the exception, which makes it difficult to find the root cause in the stack trace.

      In the following example, I ran a FacesRequest that calls a method in an "Action" class. It throws a NPE. And if I test calling the method in the class directly I also get the NPE, but the stacktrace shows me exactly where it occurs. In the NPE thrown by the FacesRequest, it only shows the request in the stacktrace.

      (Note, my requests are not directly created inside the SeamTest class, but in a class that creates different requests that I can reuse in multiple SeamTest classes.

      Here is the FacesRequest code

      test.new FacesRequest() {
       @Override
       protected void updateModelValues() throws Exception
       {
       //Set the resource selected
      
       }
      
       @Override
       protected void invokeApplication() throws Exception
       {
       //Invoke to get the Navigation Map
       invokeMethod("#{navigationAction.getNavigationMap()}");
       }
      
       @Override
       protected void renderResponse() throws Exception
       {
      
       }
       }.run();
      


      this is the exception stacktrace I see when running the test (Maven is used)

      Running myapp.ui.test.DataSourceActionTest
      java.lang.NullPointerException
       at org.jboss.seam.mock.SeamTest$Request.run(SeamTest.java:407)
       at myapp.util.NavigationRequests.getNavigationMap(NavigationRequests.java:21)
       at myapp.ui.test.DataSourceActionTest.testLeftNavigation(DataSourceActionTest.java:34)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:552)
       at org.testng.internal.Invoker.invokeMethod(Invoker.java:411)
       at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:785)
       at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:114)
       at org.testng.TestRunner.privateRun(TestRunner.java:693)
       at org.testng.TestRunner.run(TestRunner.java:574)
       at org.testng.SuiteRunner.privateRun(SuiteRunner.java:241)
       at org.testng.SuiteRunner.run(SuiteRunner.java:145)
       at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:901)
       at org.testng.TestNG.runSuitesLocally(TestNG.java:863)
       at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeTestNG(TestNGDirectoryTestSuite.java:194)
       at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:131)
       at org.apache.maven.surefire.Surefire.run(Surefire.java:129)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:288)
       at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:816)
      


      If I call the action method directly, I get the correct stacktrace I would expect to find.

      (Another Note, in stepping through the code in both examples here, they both threw the exception from the same line of code)

      NavigationAction navAction = new NavigationAction();
      navAction.getNavigationMap();


      Running myapp.ui.test.DataSourceActionTest
      java.lang.NullPointerException
       at myapp.InventoryManager.getResourcesWithType(InventoryManager.java:485)
       at myapp.impl.inventory.InventoryManager.getResourcesWithType(InventoryManager.java:483)
       at myapp.impl.inventory.InventoryManager.getResourcesWithType(InventoryManager.java:471)
       at myapp.pc.PluginContainerResourceManager.getResources(PluginContainerResourceManager.j
      ava:104)
       at myapp.ResourceManagerBean.getResourceListByCategory(ResourceManagerBean.java:56)
       at myapp.ui.NavigationAction.getNavigationMap(NavigationAction.java:76)
       at myapp.ui.test.DataSourceActionTest.getNavigationList(DataSourceActionTest.java:90)
       at myapp.ui.test.DataSourceActionTest.testLeftNavigation(DataSourceActionTest.java:34)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:552)
       at org.testng.internal.Invoker.invokeMethod(Invoker.java:411)
       at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:785)
       at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:114)
       at org.testng.TestRunner.privateRun(TestRunner.java:693)
       at org.testng.TestRunner.run(TestRunner.java:574)
       at org.testng.SuiteRunner.privateRun(SuiteRunner.java:241)
       at org.testng.SuiteRunner.run(SuiteRunner.java:145)
       at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:901)
       at org.testng.TestNG.runSuitesLocally(TestNG.java:863)
       at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeTestNG(TestNGDirectoryTestSuite.java:194)
       at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:131)
       at org.apache.maven.surefire.Surefire.run(Surefire.java:129)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:288)
       at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:816)