Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Davis2014-01-03 23:20:31 +0000
committerSam Davis2014-02-18 22:47:21 +0000
commitfaa7ae94c2e9ec77b0af6d8eae9700edfdd32e7e (patch)
treed4cadf841a1edcd73d93335d11a6f3a0133db089 /org.eclipse.mylyn.tasks.core
parentbc7ac9f9f49fb5d672ab6845faf1223b8f09eac5 (diff)
downloadorg.eclipse.mylyn.tasks-faa7ae94c2e9ec77b0af6d8eae9700edfdd32e7e.tar.gz
org.eclipse.mylyn.tasks-faa7ae94c2e9ec77b0af6d8eae9700edfdd32e7e.tar.xz
org.eclipse.mylyn.tasks-faa7ae94c2e9ec77b0af6d8eae9700edfdd32e7e.zip
357278: prevent deadlock on TaskRepository synchronized methods
See bug comment 8 Change-Id: Ia73cb74d0f446243622f8d0391b280ebd4de32c2 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=357278
Diffstat (limited to 'org.eclipse.mylyn.tasks.core')
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepository.java102
1 files changed, 59 insertions, 43 deletions
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepository.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepository.java
index 01403de77..f00c6f721 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepository.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepository.java
@@ -26,6 +26,8 @@ import java.util.TimeZone;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.PlatformObject;
+import org.eclipse.core.runtime.jobs.ILock;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.mylyn.commons.net.AuthenticationCredentials;
import org.eclipse.mylyn.commons.net.AuthenticationType;
import org.eclipse.mylyn.commons.repositories.core.ILocationService;
@@ -182,6 +184,8 @@ public final class TaskRepository extends PlatformObject {
throw new IllegalArgumentException("Unknown authentication type: " + type); //$NON-NLS-1$
}
+ private final ILock lock = Job.getJobManager().newLock();
+
private boolean isCachedUserName;
private String cachedUserName;
@@ -292,9 +296,12 @@ public final class TaskRepository extends PlatformObject {
setProperty(getKeyPrefix(AuthenticationType.PROXY) + ENABLED, null);
setProperty(getKeyPrefix(AuthenticationType.REPOSITORY) + ENABLED, null);
- synchronized (this) {
+ try {
+ lock.acquire();
transientProperties.clear();
isCachedUserName = false;
+ } finally {
+ lock.release();
}
ICredentialsStore credentialsStore = getCredentialsStore();
@@ -375,28 +382,33 @@ public final class TaskRepository extends PlatformObject {
* @return null, if no credentials are set for <code>authType</code>
* @since 3.0
*/
- public synchronized AuthenticationCredentials getCredentials(AuthenticationType authType) {
- String key = getKeyPrefix(authType);
- if (getBooleanProperty(key + ENABLED)) {
- String userName = getAuthInfo(key + USERNAME);
- String password;
-
- if (getBooleanProperty(key + SAVE_PASSWORD)) {
- password = getAuthInfo(key + PASSWORD);
+ public AuthenticationCredentials getCredentials(AuthenticationType authType) {
+ try {
+ lock.acquire();
+ String key = getKeyPrefix(authType);
+ if (getBooleanProperty(key + ENABLED)) {
+ String userName = getAuthInfo(key + USERNAME);
+ String password;
+
+ if (getBooleanProperty(key + SAVE_PASSWORD)) {
+ password = getAuthInfo(key + PASSWORD);
+ } else {
+ password = transientProperties.get(key + PASSWORD);
+ }
+
+ if (userName == null) {
+ userName = ""; //$NON-NLS-1$
+ }
+ if (password == null) {
+ password = ""; //$NON-NLS-1$
+ }
+
+ return new AuthenticationCredentials(userName, password);
} else {
- password = transientProperties.get(key + PASSWORD);
+ return null;
}
-
- if (userName == null) {
- userName = ""; //$NON-NLS-1$
- }
- if (password == null) {
- password = ""; //$NON-NLS-1$
- }
-
- return new AuthenticationCredentials(userName, password);
- } else {
- return null;
+ } finally {
+ lock.release();
}
}
@@ -615,35 +627,39 @@ public final class TaskRepository extends PlatformObject {
* memory only
* @since 3.0
*/
- public synchronized void setCredentials(AuthenticationType authType, AuthenticationCredentials credentials,
- boolean savePassword) {
- String key = getKeyPrefix(authType);
+ public void setCredentials(AuthenticationType authType, AuthenticationCredentials credentials, boolean savePassword) {
+ try {
+ lock.acquire();
+ String key = getKeyPrefix(authType);
- setBooleanProperty(key + SAVE_PASSWORD, savePassword);
+ setBooleanProperty(key + SAVE_PASSWORD, savePassword);
- if (credentials == null) {
- setBooleanProperty(key + ENABLED, false);
- transientProperties.remove(key + PASSWORD);
- addAuthInfo(null, null, key + USERNAME, key + PASSWORD);
- } else {
- setBooleanProperty(key + ENABLED, true);
- if (savePassword) {
- addAuthInfo(credentials.getUserName(), credentials.getPassword(), key + USERNAME, key + PASSWORD);
+ if (credentials == null) {
+ setBooleanProperty(key + ENABLED, false);
transientProperties.remove(key + PASSWORD);
+ addAuthInfo(null, null, key + USERNAME, key + PASSWORD);
} else {
- addAuthInfo(credentials.getUserName(), null, key + USERNAME, key + PASSWORD);
- transientProperties.put(key + PASSWORD, credentials.getPassword());
+ setBooleanProperty(key + ENABLED, true);
+ if (savePassword) {
+ addAuthInfo(credentials.getUserName(), credentials.getPassword(), key + USERNAME, key + PASSWORD);
+ transientProperties.remove(key + PASSWORD);
+ } else {
+ addAuthInfo(credentials.getUserName(), null, key + USERNAME, key + PASSWORD);
+ transientProperties.put(key + PASSWORD, credentials.getPassword());
+ }
}
- }
- if (authType == AuthenticationType.REPOSITORY) {
- if (credentials == null) {
- this.cachedUserName = null;
- this.isCachedUserName = false;
- } else {
- this.cachedUserName = credentials.getUserName();
- this.isCachedUserName = true;
+ if (authType == AuthenticationType.REPOSITORY) {
+ if (credentials == null) {
+ this.cachedUserName = null;
+ this.isCachedUserName = false;
+ } else {
+ this.cachedUserName = credentials.getUserName();
+ this.isCachedUserName = true;
+ }
}
+ } finally {
+ lock.release();
}
}

Back to the top