Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 157381 - Inconsistent IllegalAccessError in similar codepaths
Summary: Inconsistent IllegalAccessError in similar codepaths
Status: RESOLVED DUPLICATE of bug 152568
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Runtime (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: platform-runtime-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-09-14 15:14 EDT by Susan McCourt CLA
Modified: 2006-09-14 17:41 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Susan McCourt CLA 2006-09-14 15:14:03 EDT
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.
Comment 1 Thomas Watson CLA 2006-09-14 17:12:10 EDT
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.
Comment 2 Susan McCourt CLA 2006-09-14 17:41:46 EDT
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 ***