Skip to content

Commit

Permalink
fix warning about Field.isAccessible()
Browse files Browse the repository at this point in the history
'The method isAccessible() from the type AccessibleObject is deprecated
since version 9'

tested with
 WorkbenchThemeChangedHandlerTest,
 org.eclipse.ui.tests.commands.HelpContextIdTest.testHelpContextId()
  • Loading branch information
EcljpseB0T committed Jun 6, 2024
1 parent f98e933 commit 49cf3a9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,16 @@ public static final String getHelpContextId(Command command) {

String contextId = null;
if (method != null) {
boolean accessible = method.isAccessible();
method.setAccessible(true);
try {
contextId = (String) method.invoke(command);
} catch (Exception e) {
// do nothing
boolean accessible = method.canAccess(command);
if (method.trySetAccessible()) {
try {
contextId = (String) method.invoke(command);
} catch (Exception ignored) {
// do nothing
} finally {
method.setAccessible(accessible);
}
}
method.setAccessible(accessible);
}
return contextId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1254,14 +1254,15 @@ public ReflectionSupport(T instance) {
protected Object getFieldValue(Field field) {
Object value = null;
if (field != null) {
boolean accessible = field.isAccessible();
try {
field.setAccessible(true);
value = field.get(instance);
} catch (Exception exc) {
// do nothing
} finally {
field.setAccessible(accessible);
boolean accessible = field.canAccess(instance);
if (field.trySetAccessible()) {
try {
value = field.get(instance);
} catch (Exception ignored) {
// do nothing
} finally {
field.setAccessible(accessible);
}
}
}
return value;
Expand Down

0 comments on commit 49cf3a9

Please sign in to comment.