Skip to content

Commit 4e4c88a

Browse files
committed
Fix #116 : Java 16 support for ReflectionUtils (and Java 11 no warning)
1 parent 900acba commit 4e4c88a

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/main/java/org/codehaus/plexus/util/ReflectionUtils.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
* @author <a href="mailto:[email protected]">Michal Maczka</a>
3333
* @author <a href="mailto:[email protected]">Jesse McConnell</a>
3434
* @author <a href="mailto:[email protected]">Trygve Laugst&oslash;l</a>
35-
*
3635
*/
3736
public final class ReflectionUtils
3837
{
@@ -126,7 +125,7 @@ public static List<Method> getSetters( Class<?> clazz )
126125

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

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

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

221+
if ( Float.parseFloat( System.getProperty( "java.specification.version" ) ) >= 11
222+
&& Class.class.getCanonicalName().equals( clazz.getCanonicalName() ) )
223+
{
224+
// Updating Class fields accessibility is forbidden on Java 16 (and throws warning from version 11)
225+
// No concrete use case to modify accessibility at this level
226+
return;
227+
}
228+
221229
Field[] fields = clazz.getDeclaredFields();
222230

223231
AccessibleObject.setAccessible( fields, true );

0 commit comments

Comments
 (0)