Skip to content

Commit

Permalink
[java] For java 9+ make sure we use non deprecated new instance (#1169)
Browse files Browse the repository at this point in the history
  • Loading branch information
hazendaz authored Mar 5, 2024
1 parent da9e5e0 commit bb0da1b
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.assertj.core.api.Assertions.assertThat;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -81,10 +82,10 @@ public <T extends WebAssertion> T[] allByClass(String cssClass, Class<T> clazz)
private <T extends WebAssertion> T toAssertion(Element inner, Class<T> clazz) {
T assertion = null;
try {
assertion = (T) clazz.newInstance();
assertion = (T) clazz.getDeclaredConstructor().newInstance();
assertion.element = inner;
return assertion;
} catch (InstantiationException | IllegalAccessException e) {
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
throw new IllegalArgumentException(e);
}
}
Expand All @@ -106,8 +107,8 @@ private <T extends WebAssertion> T[] toArray(Elements inners, Class<T> clazz) {
for (Element element : inners) {
T assertion = null;
try {
assertion = (T) clazz.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
assertion = (T) clazz.getDeclaredConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
throw new IllegalArgumentException(e);
}
assertion.element = element;
Expand Down

0 comments on commit bb0da1b

Please sign in to comment.