Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix warning about Field.isAccessible() #1927

Merged
merged 2 commits into from
Jun 6, 2024

Conversation

jukzi
Copy link
Contributor

@jukzi jukzi commented Jun 4, 2024

'The method isAccessible() from the type AccessibleObject is deprecated since version 9'

tested with
WorkbenchThemeChangedHandlerTest,
org.eclipse.ui.tests.commands.HelpContextIdTest.testHelpContextId()

Copy link
Contributor

github-actions bot commented Jun 4, 2024

Test Results

 1 206 files   -   606   1 206 suites   - 606   1h 5m 36s ⏱️ - 31m 51s
 7 614 tests ±    0   7 382 ✅  -     4  231 💤 +  3  1 ❌ +1 
15 978 runs   - 8 016  15 464 ✅  - 7 781  513 💤  - 236  1 ❌ +1 

For more details on these failures, see this check.

Results for commit 49cf3a9. ± Comparison against base commit 1af7f4d.

This pull request skips 3 tests.
UiTestSuite org.eclipse.ui.tests.api.ApiTestSuite org.eclipse.ui.tests.api.WorkbenchPluginTest ‑ testGetImageRegistryFromAdditionalDisplay
org.eclipse.jface.text.tests.contentassist.ContextInformationTest ‑ testContextInfo_hide_focusOut
org.eclipse.urischeme.internal.registration.TestUnitWinRegistry ‑ testWinRegistry

♻️ This comment has been updated with latest results.

contextId = (String) method.invoke(command);
if (method.trySetAccessible()) {
contextId = (String) method.invoke(command);
}
} catch (Exception e) {
// do nothing
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't the finally block also need be adjusted?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also: Command#getHelpContextId() says clients shally use CommandManager#getHelpContextId(Command) instead. Can't we call that here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no final block here, `CommandManager does a lot more then just calling the method. I don't want to break anything.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, right, there is no finally block here. but the same line of thought applies:

The condition is changed from isAccessible() to canAccess(), and now the defensive if(tryAccess()) is used, but in line 266 setAccessible() is still called unconditionally which can then still fail.

I propose to also move that 'undo/cleanup' line inside the if(try) block, since otherwise there is nothing to undo and it could needlessly raise an exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

value = field.get(instance);
if (field.trySetAccessible()) {
value = field.get(instance);
}
} catch (Exception exc) {
// do nothing
} finally {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

finally block is not symmetric anymore. I think the finally can be moved inside the if(try) block.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't get what you mean with "symmetric" here or how moving the try block should help, but OK, won't hurt either.

@jukzi jukzi force-pushed the isAccessible branch 4 times, most recently from 49dcd44 to 43d14dc Compare June 5, 2024 10:59
'The method isAccessible() from the type AccessibleObject is deprecated
since version 9'

tested with
 WorkbenchThemeChangedHandlerTest,
 org.eclipse.ui.tests.commands.HelpContextIdTest.testHelpContextId()
@jukzi
Copy link
Contributor Author

jukzi commented Jun 6, 2024

unrelated random fails:
12:22:53.295 [ERROR] Failed to execute goal org.eclipse.tycho:tycho-apitools-plugin:4.0.8:verify (verify) on project org.eclipse.ui.ide: Execute ApiApplication failed: InvocationTargetException: Component 'Eclipse IDE UI' in the baseline 'workspace' is disposed: Component was disposed here -> [Help 1]
eclipse-pde/eclipse.pde#553

@jukzi jukzi merged commit 27a120d into eclipse-platform:master Jun 6, 2024
12 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants