Login | Register
My pages Projects Community openCollabNet

Discussions > dev > [Subclipse-dev] [Patch] readState() in SVNRepositories.java

subclipse
Discussion topic

Back to topic list

[Subclipse-dev] [Patch] readState() in SVNRepositories.java

Author laca
Full name Laszlo Biczok
Date 2009-02-19 02:48:13 PST
Message Hi,

If I understand the code properly, readState() creates RepositoryLocationS from the data read from a DataInputStream and adds those created to the repositories cache.
The way it does this is:

1. Creates the RepositoryLocation
2. Adds it to the cache
3. Sets the label and the repository root if certain conditions are met.

In step 2. some listeners are notified about the new RepositoryLocation (that may also notify other listeners).
As far as I can see, it is possible that some listeners may try to access the label and/or the repository root, and there is no guarantee they will see a consistent state of the RepositoryLocation (regarding the label and the repository root) or to see the real values at all at the time of their access.
So I think it would be safer to change the order of the steps and put adding to the cache as the last step.

The proposed patch is below.

Cheers,

Laca

### Eclipse Workspace Patch 1.0
#P org.tigris.subversio​n.subclipse.core
Index: src/org/tigris/subve​rsion/subclipse/core​/repo/SVNRepositorie​s.java
====================​====================​====================​=======
--- src/org/tigris/subve​rsion/subclipse/core​/repo/SVNRepositorie​s.java (revision 4302)
+++ src/org/tigris/subve​rsion/subclipse/core​/repo/SVNRepositorie​s.java (working copy)
@@ -305,19 +305,22 @@
         int count = dis.readInt();
         for(int i = 0; i < count;i++){
            ISVNRepositoryLocation root = SVNRepositoryLocatio​n.fromString(dis.rea​dUTF());
- addToRepositoriesCache(root);
- if (version >= REPOSITORIES_STATE_F​ILE_VERSION_2) {
- String label = dis.readUTF();
- if (!label.equals("")) {
- root.setLabel(label);
- }
- }
- if (version >= REPOSITORIES_STATE_F​ILE_VERSION_3) {
- String repositoryRoot = dis.readUTF();
- if (!repositoryRoot.equals("")) {
- root.setRepositoryRoot(new SVNUrl(repositoryRoot));
+ try {
+ if (version >= REPOSITORIES_STATE_F​ILE_VERSION_2) {
+ String label = dis.readUTF();
+ if (!label.equals("")) {
+ root.setLabel(label);
+ }
                 }
- }
+ if (version >= REPOSITORIES_STATE_F​ILE_VERSION_3) {
+ String repositoryRoot = dis.readUTF();
+ if (!repositoryRoot.equals("")) {
+ root.setRepositoryRoot(new SVNUrl(repositoryRoot));
+ }
+ }
+ } finally {
+ addToRepositoriesCache(root);
+ }
         }
     }

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

[Subclipse-dev] [Patch] readState() in SVNRepositories.java laca Laszlo Biczok 2009-02-19 02:48:13 PST
Messages per page: