mardi 6 octobre 2020

Get Map field from class by reflection

I am trying to access all customFields map from IssueImpl. I am afraid its private final HashMap<CustomField, Object>. I would like to use reflection.

Field field = Class.forName("com.atlassian.jira.issue.IssueImpl").getDeclaredField("customFieldValues");
field.setAccessible(true);
Map reflectEntityMap = (Map) field.get(new HashMap<CustomField,Object>());

I also found this, but not quite sure if this needs to be done:

field.set(field, field.getModifiers() & ~Modifier.FINAL);

What I am getting is:

IllegalArgumentException
Can not set final java.util.Map field com.atlassian.jira.issue.IssueImpl.customFieldValues to java.lang.reflect.Field

Not sure what I'm doing wrong





Aucun commentaire:

Enregistrer un commentaire