Skip to content

Commit ce0f105

Browse files
committed
AbstractPrefService: account for priority
It was discovered that the initialize method of multiple PrefService impls was being invoked - leading to the LOWEST priority overwriting the static service field in the Prefs utility class (since it was the last initialize method to execute). Added a check for priority so that lower priority services don't overwrite higher.
1 parent d503e31 commit ce0f105

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/main/java/org/scijava/preferences/AbstractPrefService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void initialize() {
5252

5353
@Override
5454
public void setStaticBehavior() {
55-
Prefs.setDelegateService(this);
55+
Prefs.setDelegateService(this, getPriority());
5656
}
5757

5858
}

src/main/java/org/scijava/util/Prefs.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public final class Prefs {
5656

5757
private static PrefService prefServiceNoContext;
5858

59+
private static double servicePriority = Double.MIN_VALUE;
60+
5961
private Prefs() {
6062
// prevent instantiation of utility class
6163
}
@@ -295,8 +297,13 @@ public static List<String> getList(final Preferences preferences) {
295297
/**
296298
* Sets the {@link PrefService}
297299
*/
298-
public static void setDelegateService(final PrefService prefService) {
299-
Prefs.prefService = prefService;
300+
public static void setDelegateService(final PrefService prefService,
301+
final double priority)
302+
{
303+
if (Double.compare(priority, Prefs.servicePriority) > 0) {
304+
Prefs.prefService = prefService;
305+
Prefs.servicePriority = priority;
306+
}
300307
}
301308

302309
// -- Helper methods --

0 commit comments

Comments
 (0)