mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2025-01-08 09:27:34 +01:00
Remove unsafe reflection trying to access the modifiers field (#1517)
This commit is contained in:
parent
151d4a289f
commit
baecaf4ca4
@ -395,20 +395,12 @@ public class FieldUtils {
|
||||
writeStaticField(field, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #writeStaticField(Class, String, Object, boolean)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static void writeStaticFinalField(Class<?> clazz, String fieldName, Object value, boolean forceAccess) throws Exception {
|
||||
Field field = getField(clazz, fieldName, forceAccess);
|
||||
if (field == null) {
|
||||
throw new IllegalArgumentException("Cannot locate field " + fieldName + " in " + clazz);
|
||||
}
|
||||
|
||||
field.setAccessible(true);
|
||||
|
||||
Field modifiersField = Field.class.getDeclaredField("modifiers");
|
||||
modifiersField.setAccessible(true);
|
||||
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
||||
|
||||
field.setAccessible(true);
|
||||
field.set(null, value);
|
||||
writeStaticField(clazz, fieldName, value, forceAccess);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -308,7 +308,9 @@ public class StructureModifier<TField> {
|
||||
* @param fieldIndex - index of the field.
|
||||
* @param value - TRUE if this field should be read only, FALSE otherwise.
|
||||
* @throws FieldAccessException If we cannot modify the read-only status.
|
||||
* @deprecated In recent java versions (starting at 9) the modifier field is secured and will not be writeable.
|
||||
*/
|
||||
@Deprecated
|
||||
public void setReadOnly(int fieldIndex, boolean value) throws FieldAccessException {
|
||||
if (fieldIndex < 0 || fieldIndex >= data.size())
|
||||
throw new IllegalArgumentException("Index parameter is not within [0 - " + data.size() + ")");
|
||||
@ -325,7 +327,9 @@ public class StructureModifier<TField> {
|
||||
* @param field - the field to change.
|
||||
* @param isReadOnly - TRUE if the field should be read only, FALSE otherwise.
|
||||
* @throws IllegalAccessException If an error occured.
|
||||
* @deprecated In recent java versions (starting at 9) the modifier field is secured and will not be writeable.
|
||||
*/
|
||||
@Deprecated
|
||||
protected static void setFinalState(Field field, boolean isReadOnly) throws IllegalAccessException {
|
||||
if (isReadOnly)
|
||||
FieldUtils.writeField((Object) field, "modifiers", field.getModifiers() | Modifier.FINAL, true);
|
||||
|
@ -58,8 +58,6 @@ public abstract class CompiledStructureModifier extends StructureModifier<Object
|
||||
throw new IllegalStateException("Cannot make compiled field " + fieldIndex + " read only.");
|
||||
}
|
||||
}
|
||||
|
||||
super.setReadOnly(fieldIndex, value);
|
||||
}
|
||||
|
||||
// Speed up the default writer
|
||||
|
Loading…
Reference in New Issue
Block a user