Bug 584116

Summary: WarDiscoveryHelper.getContextPath will throw a NullPointerException if contextRoot is null
Product: [Other] RHQ Project Reporter: Larry O'Leary <loleary>
Component: MonitoringAssignee: Heiko W. Rupp <hrupp>
Status: CLOSED CURRENTRELEASE QA Contact: Mike Foley <mfoley>
Severity: medium Docs Contact:
Priority: low    
Version: 1.3CC: jshaughn
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2014-05-29 11:36:28 EDT Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Description Larry O'Leary 2010-04-20 15:19:55 EDT
Description of problem:
Measurement collection for a WAR fails due to a NullPointerException that occurs while attempting to compare a null contextRoot to WarComponent.ROOT_WEBAPP_CONTEXT_ROOT.  It is not clear why the contextRoot is null but the comparison should be performed in a safer manner:

        return ((contextRoot == null || WarComponent.ROOT_WEBAPP_CONTEXT_ROOT.equals(contextRoot)) ? "/" : "/" + contextRoot);

Here is the original log messages and exception from agent.log:

2010-04-20 08:26:54,657 DEBUG [MeasurementManager.collector-1] (rhq.core.pc.inventory.ResourceContainer$ResourceComponentInvocationHandler)- Call to [org.rhq.plugins.jbossas.WarComponent.getValues()] with args [[org.rhq.core.domain.measurement.MeasurementReport@7df8170d, [ScheduledMeasurementInfo[res=900009705, name=Application.path, sched=900167388], ScheduledMeasurementInfo[res=900009705, name=Servlet.NumRequests, sched=900167828], ScheduledMeasurementInfo[res=900009705, name=Application.exploded, sched=900167432], ScheduledMeasurementInfo[res=900009705, name=Servlet.NumErrors, sched=900167916], ScheduledMeasurementInfo[res=900009705, name=ContextRoot, sched=900167476]]]] failed.
java.util.concurrent.ExecutionException: java.lang.NullPointerException
        at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:215)
        at java.util.concurrent.FutureTask.get(FutureTask.java:85)
        at org.rhq.core.pc.inventory.ResourceContainer$ResourceComponentInvocationHandler.invokeInNewThreadWithLock(ResourceContainer.java:446)
        at org.rhq.core.pc.inventory.ResourceContainer$ResourceComponentInvocationHandler.invoke(ResourceContainer.java:434)
        at $Proxy60.getValues(Unknown Source)
        at org.rhq.core.pc.measurement.MeasurementCollectorRunner.getValues(MeasurementCollectorRunner.java:111)
        at org.rhq.core.pc.measurement.MeasurementCollectorRunner.call(MeasurementCollectorRunner.java:91)
        at org.rhq.core.pc.measurement.MeasurementManager$MeasurementCollectionRequester.run(MeasurementManager.java:169)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:417)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:269)
        at java.util.concurrent.FutureTask.run(FutureTask.java:123)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:65)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:172)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:651)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:676)
        at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.NullPointerException
        at org.rhq.plugins.jbossas.util.WarDiscoveryHelper.getContextPath(WarDiscoveryHelper.java:274)
        at org.rhq.plugins.jbossas.WarComponent.getServletMetric(WarComponent.java:221)
        at org.rhq.plugins.jbossas.WarComponent.getValues(WarComponent.java:164)
        at sun.reflect.GeneratedMethodAccessor131.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.rhq.core.pc.inventory.ResourceContainer$ComponentInvocationThread.call(ResourceContainer.java:525)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:269)
        at java.util.concurrent.FutureTask.run(FutureTask.java:123)
        ... 3 more
2010-04-20 08:26:54,657 WARN  [MeasurementManager.collector-1] (rhq.core.pc.measurement.MeasurementCollectorRunner)- Failure to collect measurement data for Resource[id=900009705, type=Embedded Web Application (WAR), key=jboss.management.local:J2EEApplication=myapp.ear,J2EEServer=Local,j2eeType=WebModule,name=MyWebApp.war, name=MyWebApp.war, parent=myapp.ear], requests=[ScheduledMeasurementInfo[res=900009705, name=Application.path, sched=900167388], ScheduledMeasurementInfo[res=900009705, name=Servlet.NumRequests, sched=900167828], ScheduledMeasurementInfo[res=900009705, name=Application.exploded, sched=900167432], ScheduledMeasurementInfo[res=900009705, name=Servlet.NumErrors, sched=900167916], ScheduledMeasurementInfo[res=900009705, name=ContextRoot, sched=900167476]], report.size()=93


Version-Release number of selected component (if applicable):
JBoss ON 2.3 with EAP plug-in pack
Comment 1 Heiko W. Rupp 2010-04-22 05:40:55 EDT
Fix is in 728a80e
Comment 6 Larry O'Leary 2010-04-30 17:49:51 EDT
So just to re-sync, we believe that the proposed fix would not be sufficient as the contextRoot should have never been null in the first place but rather "/" or " - invalid - " in the event that a problem would have occurred.  By assuming "/" in the event of null, it could result in metrics still not being collected correctly based on the context-root not matching for the deployed WAR when we query it from the AS instance.

So, this method should still throw an exception.  Maybe it should throw a meaningful/descriptive one instead of a NPE?