Skip to content

Commit

Permalink
Make Config.getClass return a meaningful type
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Jun 18, 2020
1 parent bd085e8 commit 002dc3f
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 7 deletions.
4 changes: 2 additions & 2 deletions java/server/src/org/openqa/selenium/grid/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ default Optional<Boolean> getBool(String section, String option) {
return get(section, option).map(Boolean::parseBoolean);
}

default <X> Object getClass(String section, String option, Class<X> typeOfClass, String defaultClazz) {
default <X> X getClass(String section, String option, Class<X> typeOfClass, String defaultClazz) {
String clazz = get(section, option).orElse(defaultClazz);

try {
Expand All @@ -60,7 +60,7 @@ default <X> Object getClass(String section, String option, Class<X> typeOfClass,
"Class %s's `create(Config)` method must be static", clazz));
}

return create.invoke(null, this);
return typeOfClass.cast(create.invoke(null, this));
} catch (NoSuchMethodException e) {
throw new IllegalArgumentException(String.format(
"Class %s must have a static `create(Config)` method", clazz));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ public URI getDistributorUri() {
}

public Distributor getDistributor(String defaultClass) {
return (Distributor) config.getClass(DISTRIBUTOR_SECTION, "implementation", Distributor.class, defaultClass);
return config.getClass(DISTRIBUTOR_SECTION, "implementation", Distributor.class, defaultClass);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import org.openqa.selenium.grid.config.Config;
import org.openqa.selenium.internal.Require;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.logging.Logger;

public class EventBusOptions {
Expand Down Expand Up @@ -50,6 +48,6 @@ public EventBus getEventBus() {
}

private EventBus createBus() {
return (EventBus) config.getClass("events", "implementation", EventBus.class, DEFAULT_CLASS);
return config.getClass("events", "implementation", EventBus.class, DEFAULT_CLASS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ public URI getSessionMapUri() {
}

public SessionMap getSessionMap() {
return (SessionMap) config.getClass(SESSIONS_SECTION, "implementation", SessionMap.class, DEFAULT_SESSION_MAP);
return config.getClass(SESSIONS_SECTION, "implementation", SessionMap.class, DEFAULT_SESSION_MAP);
}
}

0 comments on commit 002dc3f

Please sign in to comment.