diff --git a/TODO.md b/TODO.md index c5f9c791f..11093490b 100644 --- a/TODO.md +++ b/TODO.md @@ -1,7 +1,9 @@ # 1.8.2 - - Make run with Java 21 (22?). + - Make run with Java 18+. See https://github.com/jqwik-team/jqwik/issues/528. + This may require a change to how methods are invoked via reflection. + See JqwikReflectionSupport.invokeMethodPotentiallyOuter() will probably need to accept the current property context as parameter. - Can large array shrinking be improved? See https://github.com/jqwik-team/jqwik/issues/525 diff --git a/engine/src/main/java/net/jqwik/engine/support/JqwikReflectionSupport.java b/engine/src/main/java/net/jqwik/engine/support/JqwikReflectionSupport.java index 4b925f2d3..43c218428 100644 --- a/engine/src/main/java/net/jqwik/engine/support/JqwikReflectionSupport.java +++ b/engine/src/main/java/net/jqwik/engine/support/JqwikReflectionSupport.java @@ -14,8 +14,6 @@ import net.jqwik.api.*; import net.jqwik.api.providers.*; import net.jqwik.api.support.*; -import net.jqwik.engine.properties.shrinking.*; -import net.jqwik.engine.support.types.*; import static java.util.stream.Collectors.*; @@ -47,7 +45,7 @@ private static Optional getOuterInstance(Object inner) { // but has been stable so far in all JDKs return Arrays - .stream(getDeclaredFields(inner)) + .stream(inner.getClass().getDeclaredFields()) .filter(field -> field.getName().startsWith("this$")) .findFirst() .map(field -> { @@ -62,11 +60,6 @@ private static Optional getOuterInstance(Object inner) { }); } - // Public for testing purposes only - public static Field[] getDeclaredFields(Object any) { - return any.getClass().getDeclaredFields(); - } - @SuppressWarnings("deprecation") // Deprecated as of Java 9 private static T makeAccessible(T object) { if (!object.isAccessible()) { @@ -169,7 +162,7 @@ public static List findFieldsPotentiallyOuter( public static Object readFieldPotentiallyOuter(Field field, Object target) { makeAccessible(field); - List declaredFields = Arrays.stream(getDeclaredFields(target)).collect(toList()); + List declaredFields = Arrays.stream(target.getClass().getDeclaredFields()).collect(toList()); if (declaredFields.contains(field)) { try { return field.get(target); @@ -189,7 +182,7 @@ public static Object readFieldPotentiallyOuter(Field field, Object target) { public static void setFieldPotentiallyOuter(Field field, Object value, Object target) { makeAccessible(field); - List declaredFields = Arrays.stream(getDeclaredFields(target)).collect(toList()); + List declaredFields = Arrays.stream(target.getClass().getDeclaredFields()).collect(toList()); if (declaredFields.contains(field)) { try { if (isStatic(field)) {