diff --git a/CHANGES.txt b/CHANGES.txt index d945996001..7354c4cec0 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -207,6 +207,9 @@ Trunk (unreleased changes) HADOOP-6549. TestDoAsEffectiveUser should use ip address of the host for superuser ip check(jnp via boryas) + HADOOP-6570. RPC#stopProxy throws NPE if getProxyEngine(proxy) returns + null. (hairong) + Release 0.21.0 - Unreleased INCOMPATIBLE CHANGES diff --git a/src/java/org/apache/hadoop/ipc/RPC.java b/src/java/org/apache/hadoop/ipc/RPC.java index 906d526075..36874c511d 100644 --- a/src/java/org/apache/hadoop/ipc/RPC.java +++ b/src/java/org/apache/hadoop/ipc/RPC.java @@ -244,8 +244,9 @@ public static Object getProxy(Class protocol, long clientVersion, * @param proxy the proxy to be stopped */ public static void stopProxy(Object proxy) { - if (proxy!=null) { - getProxyEngine(proxy).stopProxy(proxy); + RpcEngine rpcEngine; + if (proxy!=null && (rpcEngine = getProxyEngine(proxy)) != null) { + rpcEngine.stopProxy(proxy); } } diff --git a/src/test/core/org/apache/hadoop/ipc/TestRPC.java b/src/test/core/org/apache/hadoop/ipc/TestRPC.java index b4fd02631c..0bb3f8dc5c 100644 --- a/src/test/core/org/apache/hadoop/ipc/TestRPC.java +++ b/src/test/core/org/apache/hadoop/ipc/TestRPC.java @@ -39,6 +39,8 @@ import org.apache.hadoop.security.authorize.Service; import org.apache.hadoop.security.authorize.ServiceAuthorizationManager; +import static org.mockito.Mockito.*; + /** Unit tests for RPC. */ public class TestRPC extends TestCase { private static final String ADDRESS = "0.0.0.0"; @@ -392,6 +394,14 @@ public void testNoPings() throws Exception { conf.setBoolean("ipc.client.ping", false); new TestRPC("testnoPings").testCalls(conf); } + + /** + * Test stopping a non-registered proxy + * @throws Exception + */ + public void testStopNonRegisteredProxy() throws Exception { + RPC.stopProxy(mock(TestProtocol.class)); + } public static void main(String[] args) throws Exception {