-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #116 : Java 16 support for ReflectionUtils (and Java 11 no warnin…
…g) (#123)
- Loading branch information
Showing
1 changed file
with
10 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,6 @@ | |
* @author <a href="mailto:[email protected]">Michal Maczka</a> | ||
* @author <a href="mailto:[email protected]">Jesse McConnell</a> | ||
* @author <a href="mailto:[email protected]">Trygve Laugstøl</a> | ||
* | ||
*/ | ||
public final class ReflectionUtils | ||
{ | ||
|
@@ -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 ) | ||
{ | ||
|
@@ -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 | ||
|
@@ -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 ); | ||
|