Skip to content

Commit

Permalink
Use SecurityManager to read enum fields
Browse files Browse the repository at this point in the history
  • Loading branch information
ganadist committed Aug 4, 2021
1 parent 20720d6 commit 59a8aed
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.BitSet;
Expand Down Expand Up @@ -777,11 +779,16 @@ private static final class EnumTypeAdapter<T extends Enum<T>> extends TypeAdapte

public EnumTypeAdapter(Class<T> classOfT) {
try {
for (Field field : classOfT.getDeclaredFields()) {
for (final Field field : classOfT.getDeclaredFields()) {
if (!field.isEnumConstant()) {
continue;
}
field.setAccessible(true);
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override public Void run() {
field.setAccessible(true);
return null;
}
});
@SuppressWarnings("unchecked")
T constant = (T)(field.get(null));
String name = constant.name();
Expand Down

0 comments on commit 59a8aed

Please sign in to comment.