Address error-prone ClassNewInstance errors

Previous behavior deprecated in Java 9.
This commit is contained in:
Andrew Gaul 2016-06-03 03:18:40 -07:00
parent ed7ff648e8
commit 28ed955183
2 changed files with 10 additions and 2 deletions

View File

@ -45,6 +45,7 @@ import static org.jclouds.rest.config.BinderUtils.bindHttpApi;
import static org.jclouds.util.Throwables2.propagateAuthorizationOrOriginalException;
import java.io.Closeable;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
@ -437,11 +438,15 @@ public class ContextBuilder {
@Override
public Module apply(Class<? extends Module> arg0) {
try {
return arg0.newInstance();
return arg0.getConstructor().newInstance();
} catch (InstantiationException e) {
throw propagate(e);
} catch (IllegalAccessException e) {
throw propagate(e);
} catch (InvocationTargetException e) {
throw propagate(e);
} catch (NoSuchMethodException e) {
throw propagate(e);
}
}

View File

@ -22,6 +22,7 @@ import static org.jclouds.util.Strings2.toStringAndClose;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import org.osgi.framework.Bundle;
@ -97,9 +98,11 @@ public final class Bundles {
public T apply(Class<?> in) {
checkNotNull(in, "input class");
try {
return clazz.cast(in.newInstance());
return clazz.cast(in.getConstructor().newInstance());
} catch (InstantiationException e) {
} catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
} catch (NoSuchMethodException e) {
}
return null;
}