Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
hinerm committed Jul 25, 2014
commit ce0f105114e9ca73a3de9e8bfcee70735093f2d6
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void initialize() {

@Override
public void setStaticBehavior() {
Prefs.setDelegateService(this);
Prefs.setDelegateService(this, getPriority());
}

}
11 changes: 9 additions & 2 deletions src/main/java/org/scijava/util/Prefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public final class Prefs {

private static PrefService prefServiceNoContext;

private static double servicePriority = Double.MIN_VALUE;

private Prefs() {
// prevent instantiation of utility class
}
Expand Down Expand Up @@ -295,8 +297,13 @@ public static List<String> getList(final Preferences preferences) {
/**
* Sets the {@link PrefService}
*/
public static void setDelegateService(final PrefService prefService) {
Prefs.prefService = prefService;
public static void setDelegateService(final PrefService prefService,
final double priority)
{
if (Double.compare(priority, Prefs.servicePriority) > 0) {
Prefs.prefService = prefService;
Prefs.servicePriority = priority;
}
}

// -- Helper methods --
Expand Down