Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugene Tarassov2012-04-17 13:18:01 -0400
committerEugene Tarassov2012-04-17 13:18:01 -0400
commit8e16f7108454d72421123b1f4d1357a97e076611 (patch)
tree5866adf94aa7510ddf176c6131c38063c28d109b /plugins/org.eclipse.tcf
parent862b245909af90004bfffcc9c264401dcc40da68 (diff)
downloadorg.eclipse.tcf-8e16f7108454d72421123b1f4d1357a97e076611.tar.gz
org.eclipse.tcf-8e16f7108454d72421123b1f4d1357a97e076611.tar.xz
org.eclipse.tcf-8e16f7108454d72421123b1f4d1357a97e076611.zip
TCF Core: fixed some of FindBugs warnings, code cleanup
Diffstat (limited to 'plugins/org.eclipse.tcf')
-rw-r--r--plugins/org.eclipse.tcf/src/org/eclipse/tcf/Activator.java6
-rw-r--r--plugins/org.eclipse.tcf/src/org/eclipse/tcf/EventQueue.java10
-rw-r--r--plugins/org.eclipse.tcf/src/org/eclipse/tcf/extensions/TcfExtensionPointComparator.java9
-rw-r--r--plugins/org.eclipse.tcf/src/org/eclipse/tcf/extensions/TcfExtensionProxy.java62
-rw-r--r--plugins/org.eclipse.tcf/src/org/eclipse/tcf/ssl/TCFSecurityManager.java40
5 files changed, 73 insertions, 54 deletions
diff --git a/plugins/org.eclipse.tcf/src/org/eclipse/tcf/Activator.java b/plugins/org.eclipse.tcf/src/org/eclipse/tcf/Activator.java
index 1d5d69891..35684a48d 100644
--- a/plugins/org.eclipse.tcf/src/org/eclipse/tcf/Activator.java
+++ b/plugins/org.eclipse.tcf/src/org/eclipse/tcf/Activator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Wind River Systems, Inc. and others.
+ * Copyright (c) 2007, 2012 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -41,7 +41,8 @@ public class Activator extends Plugin {
private static final BundleListener bundle_listener = new BundleListener() {
private boolean started = false;
public void bundleChanged(BundleEvent event) {
- if (plugin != null && !started && event.getBundle() == plugin.getBundle() &&
+ if (plugin != null && !started &&
+ event.getBundle() == plugin.getBundle() &&
plugin.getBundle().getState() == Bundle.ACTIVE) {
queue.start();
started = true;
@@ -59,7 +60,6 @@ public class Activator extends Plugin {
plugin = this;
}
-
/**
* Returns the shared instance
*
diff --git a/plugins/org.eclipse.tcf/src/org/eclipse/tcf/EventQueue.java b/plugins/org.eclipse.tcf/src/org/eclipse/tcf/EventQueue.java
index fe01bae53..5fd4f564e 100644
--- a/plugins/org.eclipse.tcf/src/org/eclipse/tcf/EventQueue.java
+++ b/plugins/org.eclipse.tcf/src/org/eclipse/tcf/EventQueue.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Wind River Systems, Inc. and others.
+ * Copyright (c) 2007, 2012 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -75,15 +75,11 @@ class EventQueue implements IEventQueue, Runnable {
}
thread.join();
}
- catch (Exception e) {
+ catch (Throwable e) {
Protocol.log("Failed to shutdown TCF event dispatch thread", e); //$NON-NLS-1$
}
}
- private void error(Throwable x) {
- Protocol.log("Unhandled exception in TCF event dispatch", x); //$NON-NLS-1$
- }
-
public void run() {
for (;;) {
try {
@@ -99,7 +95,7 @@ class EventQueue implements IEventQueue, Runnable {
r.run();
}
catch (Throwable x) {
- error(x);
+ Protocol.log("Unhandled exception in TCF event dispatch", x); //$NON-NLS-1$
}
}
}
diff --git a/plugins/org.eclipse.tcf/src/org/eclipse/tcf/extensions/TcfExtensionPointComparator.java b/plugins/org.eclipse.tcf/src/org/eclipse/tcf/extensions/TcfExtensionPointComparator.java
index ab988562f..fd5b2108e 100644
--- a/plugins/org.eclipse.tcf/src/org/eclipse/tcf/extensions/TcfExtensionPointComparator.java
+++ b/plugins/org.eclipse.tcf/src/org/eclipse/tcf/extensions/TcfExtensionPointComparator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2010 Wind River Systems, Inc. and others.
+ * Copyright (c) 2009, 2012 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,12 +10,13 @@
*******************************************************************************/
package org.eclipse.tcf.extensions;
+import java.io.Serializable;
import java.util.Comparator;
import org.eclipse.core.runtime.IExtension;
/**
- * TCF extension point comparator. Used to asure that extension are
+ * TCF extension point comparator. Used to ensure that extension are
* always read in the same order.
* <p>
* The order of the extensions is defined as following:<br>
@@ -26,7 +27,9 @@ import org.eclipse.core.runtime.IExtension;
* extensions unique id</li>
* </ul>
*/
-public class TcfExtensionPointComparator implements Comparator<IExtension> {
+public class TcfExtensionPointComparator implements Comparator<IExtension>, Serializable {
+
+ private static final long serialVersionUID = 488904870541301084L;
private final static String TCF_PLUGIN_PATTERN = "org.eclipse.tcf.*"; //$NON-NLS-1$
/* (non-Javadoc)
diff --git a/plugins/org.eclipse.tcf/src/org/eclipse/tcf/extensions/TcfExtensionProxy.java b/plugins/org.eclipse.tcf/src/org/eclipse/tcf/extensions/TcfExtensionProxy.java
index 3a42c01a8..77cd6f75d 100644
--- a/plugins/org.eclipse.tcf/src/org/eclipse/tcf/extensions/TcfExtensionProxy.java
+++ b/plugins/org.eclipse.tcf/src/org/eclipse/tcf/extensions/TcfExtensionProxy.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2010 Wind River Systems, Inc. and others.
+ * Copyright (c) 2009, 2012 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -19,16 +19,16 @@ import org.eclipse.tcf.Activator;
import org.eclipse.tcf.internal.nls.TcfPluginMessages;
/**
- * TCF extension proxy implementation. The use of the proxy asures the
+ * TCF extension proxy implementation. The use of the proxy ensures the
* lazy plug-in activation policy for the contributing plug-in.
*/
public class TcfExtensionProxy<V> {
// The extension instance. Create on first access
- private V fInstance;
+ private V instance;
// The configuration element
- private final IConfigurationElement fElement;
+ private final IConfigurationElement element;
// The unique id of the extension.
- private String fId;
+ private final String id;
/**
* Constructor.
@@ -39,19 +39,15 @@ public class TcfExtensionProxy<V> {
*/
public TcfExtensionProxy(IConfigurationElement element) throws CoreException {
assert element != null;
- fElement = element;
+ this.element = element;
// The <id> attribute is mandatory.
- fId = element.getAttribute("id"); //$NON-NLS-1$
- if (fId == null || fId.trim().length() == 0) {
- throw new CoreException(new Status(IStatus.ERROR,
- Activator.PLUGIN_ID,
- 0,
+ id = element.getAttribute("id"); //$NON-NLS-1$
+ if (id == null || id.trim().length() == 0) {
+ throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0,
NLS.bind(TcfPluginMessages.Extension_error_missingRequiredAttribute, "id", element.getContributor().getName()), //$NON-NLS-1$
null));
}
-
- fInstance = null;
}
/**
@@ -59,8 +55,8 @@ public class TcfExtensionProxy<V> {
*
* @return The unique id.
*/
- public String getId() {
- return fId;
+ public final String getId() {
+ return id;
}
/**
@@ -68,34 +64,31 @@ public class TcfExtensionProxy<V> {
*
* @return The configuration element.
*/
- protected IConfigurationElement getConfigurationElement() {
- return fElement;
+ protected final IConfigurationElement getConfigurationElement() {
+ return element;
}
/**
* Returns the extension class instance. The contributing
* plug-in will be activated if not yet activated anyway.
*
- * @return The extension class instance. Might be <code>null</code> if the instanciation fails.
+ * @return The extension class instance. Might be <code>null</code> if the instantiation fails.
*/
@SuppressWarnings("unchecked")
public V getInstance() {
- if (fInstance == null) {
- IConfigurationElement element = getConfigurationElement();
- assert element != null;
- if (element != null && element.getAttribute("class") != null) { //$NON-NLS-1$
- try {
- fInstance = (V)element.createExecutableExtension("class"); //$NON-NLS-1$
- } catch (Exception e) {
- // Possible exceptions: CoreException, ClassCastException.
- IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID,
- NLS.bind(TcfPluginMessages.Extension_error_invalidExtensionPoint, element.getDeclaringExtension().getUniqueIdentifier()),
- e);
- Activator.getDefault().getLog().log(status);
- }
+ if (instance == null && element.getAttribute("class") != null) { //$NON-NLS-1$
+ try {
+ instance = (V)element.createExecutableExtension("class"); //$NON-NLS-1$
+ }
+ catch (Exception e) {
+ // Possible exceptions: CoreException, ClassCastException.
+ IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID,
+ NLS.bind(TcfPluginMessages.Extension_error_invalidExtensionPoint, element.getDeclaringExtension().getUniqueIdentifier()),
+ e);
+ Activator.getDefault().getLog().log(status);
}
}
- return fInstance;
+ return instance;
}
/* (non-Javadoc)
@@ -106,7 +99,7 @@ public class TcfExtensionProxy<V> {
// Proxies are equal if they have encapsulate an element
// with the same unique id
if (obj instanceof TcfExtensionProxy<?>) {
- return getId().equals(((TcfExtensionProxy<?>)obj).getId());
+ return id.equals(((TcfExtensionProxy<?>)obj).id);
}
return super.equals(obj);
}
@@ -117,7 +110,6 @@ public class TcfExtensionProxy<V> {
@Override
public int hashCode() {
// The hash code of a proxy is the one from the id
- return getId().hashCode();
+ return id.hashCode();
}
-
}
diff --git a/plugins/org.eclipse.tcf/src/org/eclipse/tcf/ssl/TCFSecurityManager.java b/plugins/org.eclipse.tcf/src/org/eclipse/tcf/ssl/TCFSecurityManager.java
index 4bd55cb66..55624bca0 100644
--- a/plugins/org.eclipse.tcf/src/org/eclipse/tcf/ssl/TCFSecurityManager.java
+++ b/plugins/org.eclipse.tcf/src/org/eclipse/tcf/ssl/TCFSecurityManager.java
@@ -102,7 +102,7 @@ public class TCFSecurityManager {
try {
final File usr_certs = getCertificatesDirectory();
final File sys_certs = getSysCertificatesDirectory();
- if (!usr_certs.exists()) usr_certs.mkdirs();
+ if (!usr_certs.exists() && !usr_certs.mkdirs()) throw new Exception("Cannot create directory: " + usr_certs);
final CertificateFactory cf = CertificateFactory.getInstance("X.509"); //$NON-NLS-1$
SSLContext context = SSLContext.getInstance("TLS"); //$NON-NLS-1$
@@ -111,14 +111,21 @@ public class TCFSecurityManager {
public X509Certificate[] getCertificateChain(String alias) {
File f = new File(usr_certs, "local.cert"); //$NON-NLS-1$
if (!f.exists() && sys_certs != null) f = new File(sys_certs, "local.cert"); //$NON-NLS-1$
+ InputStream inp = null;
try {
- InputStream inp = new BufferedInputStream(new FileInputStream(f));
+ inp = new BufferedInputStream(new FileInputStream(f));
X509Certificate cert = (X509Certificate)cf.generateCertificate(inp);
inp.close();
return new X509Certificate[] { cert };
}
catch (Exception x) {
Protocol.log("Cannot read certificate: " + f, x); //$NON-NLS-1$
+ try {
+ if (inp != null) inp.close();
+ }
+ catch (IOException e) {
+ Protocol.log("Cannot close certificate file: " + f, x); //$NON-NLS-1$
+ }
return null;
}
}
@@ -126,13 +133,14 @@ public class TCFSecurityManager {
public PrivateKey getPrivateKey(String alias) {
File f = new File(usr_certs, "local.priv"); //$NON-NLS-1$
if (!f.exists() && sys_certs != null) f = new File(sys_certs, "local.priv"); //$NON-NLS-1$
+ BufferedReader r = null;
try {
- BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(f), "ASCII")); //$NON-NLS-1$
+ r = new BufferedReader(new InputStreamReader(new FileInputStream(f), "ASCII")); //$NON-NLS-1$
StringBuffer bf = new StringBuffer();
boolean app = false;
for (;;) {
String s = r.readLine();
- if (s == null) new Exception("Invalid format"); //$NON-NLS-1$
+ if (s == null) throw new Exception("Invalid format"); //$NON-NLS-1$
else if (s.indexOf("-----BEGIN ") == 0) app = true; //$NON-NLS-1$
else if (s.indexOf("-----END ") == 0) break; //$NON-NLS-1$
else if (app) bf.append(s);
@@ -144,6 +152,12 @@ public class TCFSecurityManager {
}
catch (Exception x) {
Protocol.log("Cannot read private key: " + f, x); //$NON-NLS-1$
+ try {
+ if (r != null) r.close();
+ }
+ catch (IOException e) {
+ Protocol.log("Cannot close private key file: " + f, x); //$NON-NLS-1$
+ }
return null;
}
}
@@ -189,14 +203,21 @@ public class TCFSecurityManager {
ArrayList<X509Certificate> list = new ArrayList<X509Certificate>();
for (String fnm : usr_certs.list()) {
if (!fnm.endsWith(".cert")) continue; //$NON-NLS-1$
+ InputStream inp = null;
try {
- InputStream inp = new BufferedInputStream(new FileInputStream(new File(usr_certs, fnm)));
+ inp = new BufferedInputStream(new FileInputStream(new File(usr_certs, fnm)));
X509Certificate cert = (X509Certificate)cf.generateCertificate(inp);
inp.close();
list.add(cert);
}
catch (Throwable x) {
Protocol.log("Cannot load certificate: " + fnm, x); //$NON-NLS-1$
+ try {
+ if (inp != null) inp.close();
+ }
+ catch (IOException e) {
+ Protocol.log("Cannot close certificate file: " + fnm, x); //$NON-NLS-1$
+ }
}
}
if (sys_certs != null) {
@@ -204,14 +225,21 @@ public class TCFSecurityManager {
if (arr != null) {
for (String fnm : arr) {
if (!fnm.endsWith(".cert")) continue; //$NON-NLS-1$
+ InputStream inp = null;
try {
- InputStream inp = new BufferedInputStream(new FileInputStream(new File(sys_certs, fnm)));
+ inp = new BufferedInputStream(new FileInputStream(new File(sys_certs, fnm)));
X509Certificate cert = (X509Certificate)cf.generateCertificate(inp);
inp.close();
list.add(cert);
}
catch (Throwable x) {
Protocol.log("Cannot load certificate: " + fnm, x); //$NON-NLS-1$
+ try {
+ if (inp != null) inp.close();
+ }
+ catch (IOException e) {
+ Protocol.log("Cannot close certificate file: " + fnm, x); //$NON-NLS-1$
+ }
}
}
}

Back to the top