Skip to content

Commit

Permalink
replace Java 9 deprecated newInstance() with constructor.newInstance()
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Schmid <[email protected]>
  • Loading branch information
aaschmid committed Jul 10, 2018
1 parent d4db3bd commit f35c736
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static com.tngtech.java.junit.dataprovider.common.Preconditions.checkArgument;
import static com.tngtech.java.junit.dataprovider.common.Preconditions.checkNotNull;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;

Expand Down Expand Up @@ -91,14 +92,25 @@ public String getName() {
}

try {
return nameFormatter.newInstance().format(getMethod(), idx, Arrays.asList(parameters));
return nameFormatter.getDeclaredConstructor().newInstance().format(getMethod(), idx,
Arrays.asList(parameters));
} catch (InstantiationException e) {
throw new IllegalStateException(String
.format("Could not instantiate name formatter using default constructor '%s'.", nameFormatter),
e);
} catch (IllegalAccessException e) {
throw new IllegalStateException(
String.format("Default constructor not accessable of name formatter '%s'.", nameFormatter), e);
} catch (InvocationTargetException e) {
throw new IllegalStateException(String.format("Default constructor of name formatter '%s' has thrown: %s",
nameFormatter, e.getMessage()), e);
} catch (NoSuchMethodException e) {
throw new IllegalStateException(
String.format("Default constructor not found for name formatter '%s'.", nameFormatter), e);
} catch (Exception e) {
throw new IllegalStateException(String.format(
"Unexpected exception while finding and invoking default constructor of name formatter '%s': %s",
nameFormatter, e.getMessage()), e);
}
}

Expand Down

0 comments on commit f35c736

Please sign in to comment.