OK. Was able to reproduce this with the IBM JDK 7 on Linux.
I would consider this a bug in the JDK's garbage collector. It is being
overly aggressive, IMO. The code basically looks like:
client = … create client …
try {
client.callMethod(…)
} catch (Exception) {
..
}
…. never reference the client object again …
At some point in there, the GC is deciding it can garbage collect the client
proxy since it's never used again. That causes the finalizer to be called
which "closes" the ClientImpl which nulls out everything. A simple fix is to
add something like:
client.getClass();
after the call which forces the client to hang around. But this definitely is
strange behavior. Not sure what we can do to work around it. :-( No idea
why the GC is deciding it can be collected before the method even returns. Not
good. It really shouldn't be garbage collecting and finalizing something that
is obviously still on the stack.
Dan
On Nov 15, 2012, at 2:51 PM, Daniel Kulp <[email protected]> wrote:
>
> On Nov 15, 2012, at 9:09 AM, Willem jiang <[email protected]> wrote:
>> The bus is set on the client side to avoid the NPE , The most CXF related
>> Unit tests are shutdown the bus after test to clean up the resources on the
>> server side.
>> As Claus mentioned we just found the NPE is thrown from the CXF client
>> invoke method when running the test from AIX (both 1.6.x and 1.7.x)
>>
>> I saw there is a IBM JDK 6 test running against CXF trunk, but I don't see
>> this kind of NPE is thrown from CXF tests as We get from AIX like this
>>
>> Running org.apache.cxf.aegis.exception.ExceptionTest Exception in thread
>> "default-workqueue-2"
>> java.lang.NullPointerException at
>> org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:720)
>> at
>> org.apache.cxf.transport.local.LocalDestination$SynchronousConduit$1$1.run(LocalDestination.java:99)
>> at
>> org.apache.cxf.workqueue.AutomaticWorkQueueImpl$3.run(AutomaticWorkQueueImpl.java:426)
>> at
>> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1121)
>> at
>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:614)
>> at
>> org.apache.cxf.workqueue.AutomaticWorkQueueImpl$AWQThreadFactory$1.run(AutomaticWorkQueueImpl.java:351)
>>
>> at java.lang.Thread.run(Thread.java:779)
>> Tests run: 4, Failures: 0, Errors: 1, Skipped: 1, Time elapsed: 60.493 sec
>> <<< FAILURE!
>> testHeaders(org.apache.cxf.aegis.exception.ExceptionTest) Time elapsed:
>> 60.154 sec <<< ERROR!
>> java.lang.NullPointerException
>> at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:369)
>> at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:320)
>> at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:89)
>> at org.apache.cxf.frontend.ClientProxy.invoke(ClientProxy.java:81)
>> at $Proxy28.sayHiWithException(Unknown Source)
>
> The Bus would be null at this point. Not sure how that can happen. It's
> one of two things:
>
> 1) The bus is passed in as null, which would be really bad
> 2) The client has been destroyed, thus making the bus null.
>
> I would breakpoint the constructors (or add a "assert bus != null" line
> there, the test should be enabling assertions) and if it's null, try and
> figure that out.
>
> Dan
>
>
>
>
>>
>>
>> Any suggestion is appreciated.
>>
>> --
>> Willem Jiang
>>
>> Red Hat, Inc.
>> FuseSource is now part of Red Hat
>> Web: http://www.fusesource.com | http://www.redhat.com
>> Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/)
>> (English)
>> http://jnn.javaeye.com (http://jnn.javaeye.com/) (Chinese)
>> Twitter: willemjiang
>> Weibo: willemjiang
>>
>>
>>
>> On Thursday, November 15, 2012 at 9:47 PM, Claus Ibsen wrote:
>>
>>> Hi
>>>
>>> Dan thanks for sharing this. I guess we should go over the example
>>> tests and make sure they shutdown properly.
>>> Those tests Willem is trying to fix, hasn't been surfaced as often, as
>>> these tests is run last.
>>> And as many times the CI server may not get so far.
>>>
>>> What we have seen is that these tests fails more often on AIX, than
>>> the other platforms.
>>> Though we reached the end of the test suite (eg it was able to attempt
>>> all tests)
>>>
>>> So we (I guess its my work to do) can enable the AIX tests again, as
>>> we have a "complete picture" now, where those examples tests are the
>>> last issues covered.
>>>
>>> BTW: Any chance you guys have seen AIX test failures in Apache CXF
>>> project itself? And if so do you guys run on both Java6 and Java7?
>>>
>>> A piece of a stracetrace shows NPE in CXF itself, but it may be a side
>>> effect of something else.
>>>
>>> 2012-11-13 17:51:20,388 [main ] WARN PhaseInterceptorChain
>>> - Interceptor for
>>> {http://version.webservice.loanbroker.camel.apache.org/}LoanBrokerWS#{http://version.webservice.loanbroker.camel.apache.org/}getLoanQuote
>>> has thrown exception, unwinding now
>>> java.lang.NullPointerException
>>> at
>>> org.apache.cxf.endpoint.AbstractConduitSelector.getSelectedConduit(AbstractConduitSelector.java:90)
>>>
>>>
>>>
>>> On Thu, Nov 15, 2012 at 1:47 PM, Daniel Kulp <[email protected]
>>> (mailto:[email protected])> wrote:
>>>>
>>>> Willem,
>>>>
>>>> If BusFactory.newInstance().createBus() is doing something different than
>>>> BusFactory.getDefaultBus(), then likely there is a test ahead of it that
>>>> doesn't have a proper teardown that is shutting down the bus. That needs
>>>> to get fixed.
>>>>
>>>> More importantly, you are now creating a bus and not shutting it down
>>>> anywhere. Thus, you are now possibly causing issues for the next tests.
>>>> I'm OK with creating the new bus to make sure you get a clean slate, but
>>>> make sure it gets shutdown.
>>>>
>>>> Dan
>>>>
>>>>
>>>>
>>>> On Nov 15, 2012, at 12:32 AM, [email protected]
>>>> (mailto:[email protected]) wrote:
>>>>
>>>>> Author: ningjiang
>>>>> Date: Thu Nov 15 05:32:26 2012
>>>>> New Revision: 1409651
>>>>>
>>>>> URL: http://svn.apache.org/viewvc?rev=1409651&view=rev
>>>>> Log:
>>>>> Try to fix the camel-cxf related test failures
>>>>>
>>>>> Modified:
>>>>> camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerTest.java
>>>>> camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfMixedModeRouterTest.java
>>>>> camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfPayLoadBareSoapTest.java
>>>>> camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/Client.java
>>>>>
>>>>> Modified:
>>>>> camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerTest.java
>>>>> URL:
>>>>> http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerTest.java?rev=1409651&r1=1409650&r2=1409651&view=diff
>>>>> ==============================================================================
>>>>> ---
>>>>> camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerTest.java
>>>>> (original)
>>>>> +++
>>>>> camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerTest.java
>>>>> Thu Nov 15 05:32:26 2012
>>>>> @@ -104,7 +104,7 @@ public class CxfConsumerTest extends Cam
>>>>> ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
>>>>> clientBean.setAddress(SIMPLE_ENDPOINT_ADDRESS);
>>>>> clientBean.setServiceClass(HelloService.class);
>>>>> - clientBean.setBus(BusFactory.getDefaultBus());
>>>>> + clientBean.setBus(BusFactory.newInstance().createBus());
>>>>>
>>>>> HelloService client = (HelloService) proxyFactory.create();
>>>>>
>>>>>
>>>>> Modified:
>>>>> camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfMixedModeRouterTest.java
>>>>> URL:
>>>>> http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfMixedModeRouterTest.java?rev=1409651&r1=1409650&r2=1409651&view=diff
>>>>> ==============================================================================
>>>>> ---
>>>>> camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfMixedModeRouterTest.java
>>>>> (original)
>>>>> +++
>>>>> camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfMixedModeRouterTest.java
>>>>> Thu Nov 15 05:32:26 2012
>>>>> @@ -30,6 +30,7 @@ import org.apache.camel.component.cxf.co
>>>>> (http://org.apache.camel.component.cxf.co)
>>>>> import org.apache.camel.converter.jaxp.XmlConverter;
>>>>> import org.apache.camel.impl.DefaultCamelContext;
>>>>> import org.apache.camel.test.junit4.CamelTestSupport;
>>>>> +import org.apache.cxf.BusFactory;
>>>>> import org.apache.cxf.binding.soap.SoapHeader;
>>>>> import org.apache.cxf.endpoint.Server;
>>>>> import org.apache.cxf.frontend.ClientFactoryBean;
>>>>> @@ -145,7 +146,8 @@ public class CxfMixedModeRouterTest exte
>>>>> ClientProxyFactoryBean proxyFactory = new ClientProxyFactoryBean();
>>>>> ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
>>>>> clientBean.setAddress(ROUTER_ADDRESS);
>>>>> - clientBean.setServiceClass(HelloService.class);
>>>>> + clientBean.setServiceClass(HelloService.class);
>>>>> + clientBean.setBus(BusFactory.newInstance().createBus());
>>>>>
>>>>> HelloService client = (HelloService) proxyFactory.create();
>>>>> return client;
>>>>>
>>>>> Modified:
>>>>> camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfPayLoadBareSoapTest.java
>>>>> URL:
>>>>> http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfPayLoadBareSoapTest.java?rev=1409651&r1=1409650&r2=1409651&view=diff
>>>>> ==============================================================================
>>>>> ---
>>>>> camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfPayLoadBareSoapTest.java
>>>>> (original)
>>>>> +++
>>>>> camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfPayLoadBareSoapTest.java
>>>>> Thu Nov 15 05:32:26 2012
>>>>> @@ -25,6 +25,7 @@ import javax.xml.ws.Endpoint;
>>>>> import org.apache.camel.builder.RouteBuilder;
>>>>> import org.apache.camel.test.AvailablePortFinder;
>>>>> import org.apache.camel.test.junit4.CamelTestSupport;
>>>>> +import org.apache.cxf.BusFactory;
>>>>> import org.apache.cxf.frontend.ClientProxyFactoryBean;
>>>>> import org.junit.BeforeClass;
>>>>> import org.junit.Test;
>>>>> @@ -66,6 +67,7 @@ public class CxfPayLoadBareSoapTest exte
>>>>> ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
>>>>> factory.setServiceClass(BareSoapService.class);
>>>>> factory.setAddress(PROXY_URL);
>>>>> + factory.setBus(BusFactory.newInstance().createBus());
>>>>> BareSoapService client = (BareSoapService) factory.create();
>>>>>
>>>>> client.doSomething();
>>>>>
>>>>> Modified:
>>>>> camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/Client.java
>>>>> URL:
>>>>> http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/Client.java?rev=1409651&r1=1409650&r2=1409651&view=diff
>>>>> ==============================================================================
>>>>> ---
>>>>> camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/Client.java
>>>>> (original)
>>>>> +++
>>>>> camel/trunk/examples/camel-example-loan-broker/src/main/java/org/apache/camel/loanbroker/webservice/version/Client.java
>>>>> Thu Nov 15 05:32:26 2012
>>>>> @@ -38,7 +38,8 @@ public final class Client {
>>>>> ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
>>>>> clientBean.setAddress(address);
>>>>> clientBean.setServiceClass(LoanBrokerWS.class);
>>>>> - clientBean.setBus(BusFactory.getDefaultBus());
>>>>> + // just create a new bus for use
>>>>> + clientBean.setBus(BusFactory.newInstance().createBus());
>>>>> return (LoanBrokerWS) proxyFactory.create();
>>>>> }
>>>>
>>>>
>>>>
>>>> --
>>>> Daniel Kulp
>>>> [email protected] - http://dankulp.com/blog
>>>> Talend Community Coder - http://coders.talend.com
>>>
>>>
>>>
>>>
>>>
>>> --
>>> Claus Ibsen
>>> -----------------
>>> Red Hat, Inc.
>>> FuseSource is now part of Red Hat
>>> Email: [email protected] (mailto:[email protected])
>>> Web: http://fusesource.com
>>> Twitter: davsclaus
>>> Blog: http://davsclaus.com
>>> Author of Camel in Action: http://www.manning.com/ibsen
>>
>>
>>
>
> --
> Daniel Kulp
> [email protected] - http://dankulp.com/blog
> Talend Community Coder - http://coders.talend.com
>
--
Daniel Kulp
[email protected] - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com