Skip to content

Commit

Permalink
Do not assume services can always be loaded from a ModuleLayer
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Nov 9, 2020
1 parent 6187014 commit c872815
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class IkonResolver extends AbstractIkonResolver {
static {
INSTANCE = new IkonResolver();

ServiceLoader<IkonHandler> loader = ServiceLoader.load(IkonHandler.class.getModule().getLayer(), IkonHandler.class);
ServiceLoader<IkonHandler> loader = resolveServiceLoader();
for (IkonHandler handler : loader) {
HANDLERS.add(handler);
handler.setFont(Font.loadFont(handler.getFontResource().toExternalForm(), 16));
Expand All @@ -43,6 +43,13 @@ private IkonResolver() {

}

private static ServiceLoader<IkonHandler> resolveServiceLoader() {
if (null != IkonHandler.class.getModule().getLayer()) {
return ServiceLoader.load(IkonHandler.class.getModule().getLayer(), IkonHandler.class);
}
return ServiceLoader.load(IkonHandler.class);
}

public static IkonResolver getInstance() {
return INSTANCE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class IkonResolver extends AbstractIkonResolver {
static {
INSTANCE = new IkonResolver();

ServiceLoader<IkonHandler> loader = ServiceLoader.load(IkonHandler.class.getModule().getLayer(), IkonHandler.class);
ServiceLoader<IkonHandler> loader = resolveServiceLoader();
for (IkonHandler handler : loader) {
HANDLERS.add(handler);

Expand All @@ -54,6 +54,13 @@ private IkonResolver() {

}

private static ServiceLoader<IkonHandler> resolveServiceLoader() {
if (null != IkonHandler.class.getModule().getLayer()) {
return ServiceLoader.load(IkonHandler.class.getModule().getLayer(), IkonHandler.class);
}
return ServiceLoader.load(IkonHandler.class);
}

public static IkonResolver getInstance() {
return INSTANCE;
}
Expand Down

0 comments on commit c872815

Please sign in to comment.