Skip to content

Fix #116 : Java 16 support for ReflectionUtils #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/main/java/org/codehaus/plexus/util/ReflectionUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
* @author <a href="mailto:michal@codehaus.org">Michal Maczka</a>
* @author <a href="mailto:jesse@codehaus.org">Jesse McConnell</a>
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
*
*/
public final class ReflectionUtils
{
Expand Down Expand Up @@ -126,7 +125,7 @@ public static List<Method> getSetters( Class<?> clazz )

/**
* @param method the method
* @return the class of the argument to the setter. Will throw an RuntimeException if the method isn't a setter.
* @return the class of the argument to the setter. Will throw an RuntimeException if the method isn't a setter.
*/
public static Class<?> getSetterType( Method method )
{
Expand Down Expand Up @@ -163,6 +162,7 @@ public static void setVariableValueInObject( Object object, String variable, Obj

/**
* Generates a map of the fields and values on a given object, also pulls from superclasses
*
* @param variable field name
* @param object the object to generate the list of fields from
* @return map containing the fields and their values
Expand Down Expand Up @@ -218,6 +218,14 @@ private static void gatherVariablesAndValuesIncludingSuperclasses( Object object

Class<?> clazz = object.getClass();

if ( Float.parseFloat( System.getProperty( "java.specification.version" ) ) >= 11
&& Class.class.getCanonicalName().equals( clazz.getCanonicalName() ) )
{
// Updating Class fields accessibility is forbidden on Java 16 (and throws warning from version 11)
// No concrete use case to modify accessibility at this level
return;
}

Field[] fields = clazz.getDeclaredFields();

AccessibleObject.setAccessible( fields, true );
Expand Down