[java] Throw a WebDriverException instead of returning logging and returning
null. If these code paths ever triggered, the returned null would just
result in a NullPointerException.
Also collapsing some redundant catch blocks.
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
-import java.util.logging.Level;
import java.util.logging.Logger;
/**
@@ -67,15 +66,11 @@ public WebDriver newInstance(Capabilities capabilities) {
private Class<? extends WebDriver> getDriverClass(String driverClassName) {
try {
return Class.forName(driverClassName).asSubclass(WebDriver.class);
- } catch (ClassNotFoundException e) {
- LOG.log(Level.INFO, "Driver class not found: " + driverClassName);
- return null;
- } catch (NoClassDefFoundError e) {
- LOG.log(Level.INFO, "Driver class not found: " + driverClassName);
- return null;
+ } catch (ClassNotFoundException | NoClassDefFoundError e) {
+ throw new WebDriverException("Driver class not found: " + driverClassName);
} catch (UnsupportedClassVersionError e) {
- LOG.log(Level.INFO, "Driver class is built for higher Java version: " + driverClassName);
- return null;
+ throw new WebDriverException(
+ "Driver class is built for higher Java version: " + driverClassName);
}
}
@@ -87,16 +82,10 @@ private WebDriver callConstructor(String driverClassName, Capabilities capabilit
} catch (NoSuchMethodException e) {
try {
return from.newInstance();
- } catch (InstantiationException e1) {
- throw new WebDriverException(e);
- } catch (IllegalAccessException e1) {
+ } catch (InstantiationException | IllegalAccessException e1) {
throw new WebDriverException(e);
}
- } catch (InvocationTargetException e) {
- throw new WebDriverException(e);
- } catch (InstantiationException e) {
- throw new WebDriverException(e);
- } catch (IllegalAccessException e) {
+ } catch (InvocationTargetException | InstantiationException | IllegalAccessException e) {
throw new WebDriverException(e);
}
}
