Skip to content
Permalink
Browse files

safe handling of static InstanceManager (SpotBugs flagged)

  • Loading branch information...
silverailscolo committed Jun 6, 2019
1 parent 457090e commit d142b769fdfacd2b14dc4f20d66504c9a3191a08
Showing with 19 additions and 4 deletions.
  1. +19 −4 java/src/jmri/InstanceManager.java
@@ -809,8 +809,8 @@ public void clearAll() {
log.debug("Clearing InstanceManager");
if (traceFileActive) traceFileWriter.println("clearAll");

// replace the instance manager, so future calls will invoke the new one
LazyInstanceManager.instanceManager = new InstanceManager();
// reset the instance manager, so future calls will invoke the new one
LazyInstanceManager.resetInstanceManager();

// continue to clean up this one
new HashSet<>(managerLists.keySet()).forEach((type) -> {
@@ -855,7 +855,22 @@ public void clearAll() {
*/
private static class LazyInstanceManager {

public static InstanceManager instanceManager = new InstanceManager();
private static InstanceManager instanceManager = new InstanceManager();

/**
* Get the InstanceManager.
*/
public static InstanceManager getInstanceManager() {
return instanceManager;
}

/**
* Replace the (static) InstanceManager.
*/
public static void resetInstanceManager() {
instanceManager = new InstanceManager();
}

}

/**
@@ -867,7 +882,7 @@ public void clearAll() {
*/
@Nonnull
public static InstanceManager getDefault() {
return LazyInstanceManager.instanceManager;
return LazyInstanceManager.getInstanceManager();
}

// support checking for overlapping intialization

0 comments on commit d142b76

Please sign in to comment.
You can’t perform that action at this time.