Skip to content

Commit

Permalink
Ensure that AbstractRepository.properties cannot be replaced
Browse files Browse the repository at this point in the history
- Make AbstractRepository.properties final.
- Modify AbstractRepository.setProperties to do a clear and a putAll.
- Make the only method that accesses AbstractRepository.properties
without synchronization, AbstractRepository.getProperty(String), also be
synchronized.

eclipse-tycho/tycho#4709
  • Loading branch information
merks committed Feb 12, 2025
1 parent 49b9bf5 commit 5b57f58
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public abstract class AbstractRepository<T> extends PlatformObject implements IR
private String description;
private transient URI location;
private String name;
private Map<String, String> properties = new OrderedProperties();
private final Map<String, String> properties = new OrderedProperties();
private String provider;
private String type;
private String version;
Expand Down Expand Up @@ -111,7 +111,7 @@ public synchronized Map<String, String> getProperties() {
}

@Override
public String getProperty(String key) {
public synchronized String getProperty(String key) {
return properties.get(key);
}

Expand Down Expand Up @@ -236,7 +236,8 @@ protected synchronized void setVersion(String version) {
* @param properties the repository provider
*/
protected synchronized void setProperties(Map<String, String> properties) {
this.properties = properties;
this.properties.clear();
this.properties.putAll(properties);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ protected class MirrorRepo extends AbstractArtifactRepository {
}

@Override
public String getProperty(String key) {
public synchronized String getProperty(String key) {
return getProperties().get(key);
}

Expand Down

0 comments on commit 5b57f58

Please sign in to comment.