/** * Force the field to be modifiable and accessible. */ protected static void makeModifiable(Field nameField) throws Exception { nameField.setAccessible(true); int modifiers = nameField.getModifiers(); Field modifierField = nameField.getClass().getDeclaredField("modifiers"); modifiers = modifiers & ~Modifier.FINAL; modifierField.setAccessible(true); modifierField.setInt(nameField, modifiers); }