Skip to content

Commit

Permalink
EclipsePreferences: mt hardening
Browse files Browse the repository at this point in the history
volatile booleans,
final descriptor
  • Loading branch information
jukzi committed Jan 24, 2025
1 parent 6ef3b0b commit e0810d0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class EclipsePreferences implements IEclipsePreferences, IScope {
protected static final String EMPTY_STRING = ""; //$NON-NLS-1$
private static final String BACKUP_FILE_EXTENSION = ".bak"; //$NON-NLS-1$

/** not synchronized, but each thread would create the same result **/
private String cachedPath;
/** synchronized by childAndPropertyLock */
private ImmutableMap properties = ImmutableMap.EMPTY;
Expand All @@ -65,16 +66,16 @@ public class EclipsePreferences implements IEclipsePreferences, IScope {
* Protects write access to properties and children.
*/
private final Object childAndPropertyLock = new Object();
protected boolean dirty = false;
protected boolean loading = false;
protected volatile boolean dirty;
protected volatile boolean loading;
protected final String name;
// the parent of an EclipsePreference node is always an EclipsePreference node.
// (or null)
protected final EclipsePreferences parent;
protected boolean removed = false;
protected volatile boolean removed;
private final ListenerList<INodeChangeListener> nodeChangeListeners = new ListenerList<>();
private final ListenerList<IPreferenceChangeListener> preferenceChangeListeners = new ListenerList<>();
private ScopeDescriptor descriptor;
private final ScopeDescriptor descriptor;

public static final boolean DEBUG_PREFERENCE_GENERAL;
public static final boolean DEBUG_PREFERENCE_SET;
Expand All @@ -91,9 +92,14 @@ public EclipsePreferences() {
}

protected EclipsePreferences(EclipsePreferences parent, String name) {
this(parent, name, null);
}

EclipsePreferences(EclipsePreferences parent, String name, ScopeDescriptor descriptor) {
this.parent = parent;
this.name = name;
this.cachedPath = null; // make sure the cached path is cleared after setting the parent
this.descriptor = descriptor;
}

@Override
Expand Down Expand Up @@ -579,8 +585,7 @@ public long getLong(String key, long defaultValue) {
}

protected EclipsePreferences internalCreate(EclipsePreferences nodeParent, String nodeName, Object context) {
EclipsePreferences result = new EclipsePreferences(nodeParent, nodeName);
result.descriptor = this.descriptor;
EclipsePreferences result = new EclipsePreferences(nodeParent, nodeName, descriptor);
return result;
}

Expand Down Expand Up @@ -1141,10 +1146,6 @@ public String toString() {
return absolutePath();
}

void setDescriptor(ScopeDescriptor descriptor) {
this.descriptor = descriptor;
}

protected IEclipsePreferences getOrCreate(String scope) {
IEclipsePreferences child;
synchronized (childAndPropertyLock) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ public IEclipsePreferences createNode(RootPreferences parent, String name) {
try {
Object storage = element.createExecutableExtension(ATTRIBUTE_STORAGE);
ScopeDescriptor descriptor = new ScopeDescriptor((AbstractPreferenceStorage) storage);
EclipsePreferences result = new EclipsePreferences(parent, name);
result.setDescriptor(descriptor);
EclipsePreferences result = new EclipsePreferences(parent, name, descriptor);
return result;
} catch (ClassCastException e) {
RuntimeLog.log(Status.error(PrefsMessages.preferences_classCastStorage, e));
Expand Down

0 comments on commit e0810d0

Please sign in to comment.