From d0452af68fbe35aaf723337ca74aeddf0cc5d42b Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Fri, 21 Jun 2013 11:16:55 +0200 Subject: [PATCH] EA-45804 (NPE: SocksAuthenticatorManager.unregister) --- .../connections/ssh/SocksAuthenticatorManager.java | 10 +++++++--- .../connections/ssh/SshProxyFactory.java | 13 ++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/connections/ssh/SocksAuthenticatorManager.java b/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/connections/ssh/SocksAuthenticatorManager.java index e4ca2c4880f8..4a310d33d943 100644 --- a/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/connections/ssh/SocksAuthenticatorManager.java +++ b/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/connections/ssh/SocksAuthenticatorManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,7 @@ */ package com.intellij.cvsSupport2.connections.ssh; +import com.intellij.cvsSupport2.config.ProxySettings; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.util.KeyValue; import com.intellij.openapi.util.Pair; @@ -30,9 +31,9 @@ import java.util.List; import java.util.Map; public class SocksAuthenticatorManager { - private final static String SOCKS_REQUESTING_PROTOCOL = "SOCKS"; + private final Object myLock; - private CvsProxySelector mySelector; + private volatile CvsProxySelector mySelector; public static SocksAuthenticatorManager getInstance() { return ServiceManager.getService(SocksAuthenticatorManager.class); @@ -53,6 +54,9 @@ public class SocksAuthenticatorManager { public void unregister(final ConnectionSettings connectionSettings) { SshLogger.debug("unregister in authenticator"); + if (!connectionSettings.isUseProxy()) return; + final int proxyType = connectionSettings.getProxyType(); + if (proxyType != ProxySettings.SOCKS4 && proxyType != ProxySettings.SOCKS5) return; mySelector.unregister(connectionSettings.getHostName(), connectionSettings.getPort()); CommonProxy.getInstance().removeCustomAuth(getClass().getName()); } diff --git a/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/connections/ssh/SshProxyFactory.java b/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/connections/ssh/SshProxyFactory.java index 02611b0e74f1..097002545145 100644 --- a/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/connections/ssh/SshProxyFactory.java +++ b/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/connections/ssh/SshProxyFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,19 +26,18 @@ import java.io.IOException; import java.net.Socket; public class SshProxyFactory { - private SshProxyFactory() { - } + + private SshProxyFactory() {} @Nullable public static ProxyData createAndRegister(final ConnectionSettings connectionSettings) { - ProxyData result = null; - if (! connectionSettings.isUseProxy()) return null; + if (!connectionSettings.isUseProxy()) return null; final int type = connectionSettings.getProxyType(); - if ((ProxySettings.SOCKS4 == type) || (ProxySettings.SOCKS5 == type)) { + ProxyData result = null; + if (ProxySettings.SOCKS4 == type || ProxySettings.SOCKS5 == type) { result = new SocksProxyData(connectionSettings); SocksAuthenticatorManager.getInstance().register(connectionSettings); } else if (ProxySettings.HTTP == type) { - /*String proxyHost, int proxyPort, String proxyUser, String proxyPass*/ result = new HTTPProxyData(connectionSettings.getProxyHostName(), connectionSettings.getProxyPort(), connectionSettings.getProxyLogin(), connectionSettings.getProxyPassword()); }