Skip to content

Commit

Permalink
Fix #116 : Java 16 support for ReflectionUtils (and Java 11 no warnin…
Browse files Browse the repository at this point in the history
…g) (#123)
  • Loading branch information
axel3rd committed Apr 5, 2021
1 parent 9d76e46 commit 6f11ee1
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/main/java/org/codehaus/plexus/util/ReflectionUtils.java
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

0 comments on commit 6f11ee1

Please sign in to comment.