Community
Participate
Working Groups
Using I20060912-0800, WinXP, j2re1.4.2_08 I have two different cases where accessing a protected method from an inner class, an IAdaptable, behave inconsistently. SCENARIO ONE causes an IllegalAccessError and the other does not. I'm not sure if the inconsistency itself is a problem, or if I'm missing some subtle difference. Note that the examples may not necessarily be released to HEAD, as we were working off patches in bug #154779. SCENARIO ONE: Inside a class "AddMarkerAction" I create the following IAdaptable which is accessed and run from another class that was passed the adaptable: PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute (op, null, new IAdaptable() { public Object getAdapter(Class clazz) { if (clazz == Shell.class && getTextEditor() != null) { return getTextEditor().getSite().getShell(); } return null; } }); Note that the getAdapter method contains a reference to a protected method in the outer class. The method is getTextEditor(). So when the adaptable's getAdapter(...) method is run, I get this stack trace: !ENTRY org.eclipse.ui 4 0 2006-09-13 11:38:46.315 !MESSAGE tried to access method org.eclipse.ui.texteditor.TextEditorAction.getTextEditor()Lorg/eclipse/ui/texteditor/ITextEditor; from class org.eclipse.ui.texteditor.AddMarkerAction$1 !STACK 0 java.lang.IllegalAccessError: tried to access method org.eclipse.ui.texteditor.TextEditorAction.getTextEditor()Lorg/eclipse/ui/texteditor/ITextEditor; from class org.eclipse.ui.texteditor.AddMarkerAction$1 at org.eclipse.ui.texteditor.AddMarkerAction$1.getAdapter(AddMarkerAction.java:136) at org.eclipse.ui.internal.operations.AdvancedValidationUserApprover.getShell(AdvancedValidationUserApprover.java:390) I can avoid this error by using the following code instead: final ITextEditor editor = getTextEditor(); PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute (op, null, new IAdaptable() { public Object getAdapter(Class clazz) { if (clazz == Shell.class && editor != null) { return editor.getSite().getShell(); } return null; } }); SCENARIO TWO: Similar situation in a different class, MarkerRulerAction. The code is as follows: PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute (operation, null, new IAdaptable() { public Object getAdapter(Class clazz) { if (clazz == Shell.class && getTextEditor() != null) { return getTextEditor().getSite().getShell(); } return null; } }); The getTextEditor() method is also protected in this class. However, when the adaptable is run, there is no IllegalAccessError. I put breakpoints in the code in both cases and stepped through to make sure the code was reached. Questions: Q1- If the first case is illegal, shouldn't the compiler have caught it? Q2- Why wouldn't the second case be illegal? The only difference I can observe is that in case 1, the protected method is inherited from a superclass of the outer class creating the adaptable. And in case 2, the protected method is directly implemented in the outer class creating the adaptable.
Are we dealing with split packages in either of these scenarios? In SCENARIO ONE is the super class org.eclipse.ui.texteditor.TextEditorAction in the same bundle as the out class org.eclipse.ui.texteditor.AddMarkerAction? If the org.eclipse.ui.texteditor package is split then see bug 152568 for an explanation of why this can fail.
yes, this is exactly the case. The package is split across plug-ins. AddMarkerAction is in the org.eclipse.ui.editors plugin and TextEditorAction is in the org.eclipse.ui.workbench.texteditor plug-in. I'll mark this as a duplicate of #152568 and add an annotation there about the time spent due to the lack of a compile error. (lesson learned, I could have saved the time spent writing this up by bugzilla searching on IllegalAccessError!) *** This bug has been marked as a duplicate of 152568 ***