[ 
https://issues.apache.org/jira/browse/ZOOKEEPER-1683?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13628622#comment-13628622
 ] 

Shevek commented on ZOOKEEPER-1683:
-----------------------------------

I think you can't just check isConnected() / sockKey != null because it's being 
set to null on a different thread, so then there will be a race for the NPE 
instead of just an NPE.

One of the other issues with this thread contract, where values are set within 
an object which is accessible to more than one thread is that JSR133 says that 
assignments performed in constructors do not happen-before the constructor 
returns unless the variable being assigned is final. Since ClientCnxnNIO is 
accessible to more than one thread at the point variables like sockKey are 
initialized, I suspect the code violates the JMM anyway.

A much better solution would be to use more immutable variables, and discard 
and reconstruct objects rather than attempting to modify them. An ideal 
solution would be to use something like netty, which is designed to handle and 
abstract all these cases.
                
> ZooKeeper client NPE when updating server list on disconnected client
> ---------------------------------------------------------------------
>
>                 Key: ZOOKEEPER-1683
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1683
>             Project: ZooKeeper
>          Issue Type: Bug
>          Components: java client
>    Affects Versions: 3.5.0
>            Reporter: Shevek
>            Assignee: Alexander Shraer
>             Fix For: 3.5.0
>
>         Attachments: ZOOKEEPER-1683.patch, ZOOKEEPER-1683-ver1.patch
>
>
> 2013-04-04 22:16:15,872 ERROR [pool-4-thread-1] 
> com.netflix.curator.ConnectionState.getZooKeeper (ConnectionState.java:84) - 
> Background exception caught
> java.lang.NullPointerException
>         at 
> org.apache.zookeeper.client.StaticHostProvider.updateServerList(StaticHostProvider.java:161)
>  ~[zookeeper-3.5.0.jar:3.5.0--1]
>         at 
> org.apache.zookeeper.ZooKeeper.updateServerList(ZooKeeper.java:183) 
> ~[zookeeper-3.5.0.jar:3.5.0--1]
>         at 
> com.netflix.curator.HandleHolder$1$1.setConnectionString(HandleHolder.java:121)
>  ~[curator-client-1.3.5-SNAPSHOT.jar:?]
> The duff code is this:
> ClientCnxnSocket clientCnxnSocket = cnxn.sendThread.getClientCnxnSocket();
> InetSocketAddress currentHost = (InetSocketAddress) 
> clientCnxnSocket.getRemoteSocketAddress();
> boolean reconfigMode = hostProvider.updateServerList(serverAddresses, 
> currentHost);
> Now, currentHost might be null, if we're not yet connected. But 
> StaticHostProvider.updateServerList indirects on it unconditionally.
> This would be caught by findbugs.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to