Bug 178912 - IVMInstallType api and AbstractVMInstallType impl are not
thread safe
diff --git a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/AbstractVMInstallType.java b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/AbstractVMInstallType.java
index ddc5952..e7a5c27 100644
--- a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/AbstractVMInstallType.java
+++ b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/AbstractVMInstallType.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2014 IBM Corporation 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
@@ -49,7 +49,7 @@
* Subclasses should not override this method.
* @see IVMType#getVMs()
*/
- public IVMInstall[] getVMInstalls() {
+ public synchronized IVMInstall[] getVMInstalls() {
IVMInstall[] vms= new IVMInstall[fVMs.size()];
return fVMs.toArray(vms);
}
@@ -59,12 +59,14 @@
* @see IVMType#disposeVM(String)
*/
public void disposeVMInstall(String id) {
- for (int i= 0; i < fVMs.size(); i++) {
- IVMInstall vm= fVMs.get(i);
- if (vm.getId().equals(id)) {
- fVMs.remove(i);
- JavaRuntime.fireVMRemoved(vm);
- return;
+ synchronized (this) {
+ for (int i= 0; i < fVMs.size(); i++) {
+ IVMInstall vm= fVMs.get(i);
+ if (vm.getId().equals(id)) {
+ fVMs.remove(i);
+ JavaRuntime.fireVMRemoved(vm);
+ return;
+ }
}
}
}
@@ -74,10 +76,12 @@
* @see IVMType#getVM(String)
*/
public IVMInstall findVMInstall(String id) {
- for (int i= 0; i < fVMs.size(); i++) {
- IVMInstall vm= fVMs.get(i);
- if (vm.getId().equals(id)) {
- return vm;
+ synchronized (this) {
+ for (int i = 0; i < fVMs.size(); i++) {
+ IVMInstall vm = fVMs.get(i);
+ if (vm.getId().equals(id)) {
+ return vm;
+ }
}
}
return null;
@@ -92,8 +96,11 @@
String format= LaunchingMessages.vmInstallType_duplicateVM;
throw new IllegalArgumentException(NLS.bind(format, new String[] { id }));
}
- IVMInstall vm= doCreateVMInstall(id);
- fVMs.add(vm);
+ IVMInstall vm = null;
+ synchronized (this) {
+ vm = doCreateVMInstall(id);
+ fVMs.add(vm);
+ }
return vm;
}
@@ -138,10 +145,12 @@
* @see org.eclipse.jdt.launching.IVMInstallType#findVMInstallByName(java.lang.String)
*/
public IVMInstall findVMInstallByName(String name) {
- for (int i= 0; i < fVMs.size(); i++) {
- IVMInstall vm= fVMs.get(i);
- if (vm.getName().equals(name)) {
- return vm;
+ synchronized (this) {
+ for (int i = 0; i < fVMs.size(); i++) {
+ IVMInstall vm = fVMs.get(i);
+ if (vm.getName().equals(name)) {
+ return vm;
+ }
}
}
return null;