Skip to content

Commit 3b99ca8

Browse files
committed
Do not create new singleton plugin instances
Instead, throw an exception with a hint. This will hopefully avoid logic errors in downstream code, which attempt to create new instances of singleton plugins.
1 parent 04b08df commit 3b99ca8

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/main/java/org/scijava/plugin/AbstractSingletonService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ public <P extends PT> P getInstance(final Class<P> pluginClass) {
8080
return (P) instanceMap.get(pluginClass);
8181
}
8282

83+
// -- PTService methods --
84+
85+
@Override
86+
public <P extends PT> P create(final Class<P> pluginClass) {
87+
throw new UnsupportedOperationException(
88+
"Cannot create singleton plugin instance. "
89+
+ "Use getInstance(Class) instead.");
90+
}
91+
8392
// -- Service methods --
8493

8594
@Override

0 commit comments

Comments
 (0)