Bug 168331 - [1.5][compiler] AbstractMethodError on interface method
Summary: [1.5][compiler] AbstractMethodError on interface method
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows 2000
: P3 normal with 3 votes (vote)
Target Milestone: 3.3 M5   Edit
Assignee: Maxime Daniel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 173477 176528 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-12-16 13:16 EST by Stefan Mücke CLA
Modified: 2007-03-06 15:29 EST (History)
9 users (show)

See Also:


Attachments
Fix plus test cases activation (4.46 KB, patch)
2007-01-10 10:16 EST, Maxime Daniel CLA
no flags Details | Diff
Fix + test cases - improved (11.71 KB, patch)
2007-01-11 15:12 EST, Maxime Daniel CLA
no flags Details | Diff
Smaller fix only addresses regression (9.31 KB, patch)
2007-01-15 07:15 EST, Maxime Daniel CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Mücke CLA 2006-12-16 13:16:23 EST
Build ID: I20061214-1445
Java Version: 6.0

Eclipse 3.3 M4 introduced a bug in the compiler, which results in an AbstractMethodError at runtime. However, the affected code worked before, and the compiler doesn't complain anything at compile time.

The following code reproduces the error:

package bugs;

public class AbstractMethodErrorBug {

	public static interface IListEntry {
	}

	public static interface IExtendedListEntry extends IListEntry {
	}

	public static interface IList {
		IListEntry getEntry(int index);
	}

	public static interface IExtendedList extends IList {
		IExtendedListEntry getEntry(int index);
	}

	public static class ExtendedList implements IExtendedList {
		public IExtendedListEntry getEntry(int index) {
			return null;
		}
	}

	private IList list = new ExtendedList();

	public AbstractMethodErrorBug() {
	}

	public void testAbstractMethodErrorBug() {
		list.getEntry(0); // causes an AbstractMethodError
		System.out.println("Bug has been fixed :-)");
	}

	public static void main(String[] args) {
		new AbstractMethodErrorBug().testAbstractMethodErrorBug();
	}
}
Comment 1 Olivier Thomann CLA 2006-12-16 13:44:17 EST
The bug has been introduced between 3.3M3 and 3.3M4.
Comment 2 Stephan Michels CLA 2006-12-18 05:15:12 EST
I got a similar problem with my projects. I assume that it is caused by the same issue. There is my test class to reproduce the error:

public class Test
{
  public interface IProperty
  {
    public String getValue();
  }
  
  public interface IPropertyContainer
  {
    public IProperty getProperty();
  }
  
  public static class EntityProperty implements IProperty
  {
    public String getValue()
    {
      return "test";
    }
  }
  
  public interface IEntity extends IPropertyContainer
  {
    public EntityProperty getProperty();
  }
  
  public static abstract class AbstractEntity implements IEntity
  {
    public EntityProperty getProperty()
    {
      return new EntityProperty();
    }
  }
  
  public static class Entity extends AbstractEntity
  {
  }
  
  public static void main( String[] args )
  {
    IEntity entity = new Entity();
    System.out.println("value="+entity.getProperty().getValue());
    IPropertyContainer container = entity;
    System.out.println("value="+container.getProperty().getValue());
  }
}
Comment 3 Olivier Thomann CLA 2006-12-19 19:12:25 EST
v_722 compiles it fine and v_723 fails.
This narrows down when the problem was introduced.
Comment 4 Maxime Daniel CLA 2007-01-08 11:31:01 EST
Will investigate.
Comment 5 Maxime Daniel CLA 2007-01-09 07:23:59 EST
Released InnerEmulationTest#133 and 134 (inactive) in HEAD.
Considering test133 test case, we miss a bridge method in X$Y.class, which was properly generated until v_723.
Comment 6 Maxime Daniel CLA 2007-01-09 08:30:12 EST
Released InnerEmulationTest#133 and 134 (active) in R3_2_maintenance.
Comment 7 Maxime Daniel CLA 2007-01-09 11:02:53 EST
This is a regression introduced by the fix for bug 162073. In fact, we must delay the elimination from the inherited methods of the interface methods that are implemented, so as to enable the bridge methods generation. The more recent fix for bug 161541 eliminates duplicates later in the process (to fulfill other needs), which happens to fix bug 162073 as well, modulo a few changes in error messages.
I will revert the change for bug 162073 and clarify the semantics of isInterfaceMethodImplemented, fix the error messages and see where we get.
Comment 8 Maxime Daniel CLA 2007-01-09 11:58:03 EST
Erratum: bug 162073 is *not* fixed if I remove the change. Need to be more cautious here. There is a tension between the needs of method verification (namely  catch truly incompatible return types) and of bridge methods generation (need a bridge method if the return type is compatible but different).
Comment 9 Maxime Daniel CLA 2007-01-10 10:16:13 EST
Created attachment 56701 [details]
Fix plus test cases activation

This fix does the following:
- it reverts to v_722 for the construction of the inheritedMethods collection (in
  the method verifier);
- while verifying the inherited methods in MethodVerifier15#checkInheritedMethods,
  it suppresses overriden methods from implemented/inherited interfaces before
  delegating the ultimate checks to MethodVerifier#checkInheritedMethods.

Currently under test.
Comment 10 Maxime Daniel CLA 2007-01-11 15:12:39 EST
Created attachment 56796 [details]
Fix + test cases - improved

This fix builds upon the ideas of the first one, and especially gets rid of the
initial fix for bug 162073, but:
- eliminates overridden methods later, and only does so for a specific check (does 
  not keep the results for further use);
- uses a better criterion to eliminate the overridden methods.
Comment 11 Maxime Daniel CLA 2007-01-15 07:13:47 EST
Released for 3.3 M5.
Comment 12 Maxime Daniel CLA 2007-01-15 07:15:19 EST
Created attachment 56896 [details]
Smaller fix only addresses regression

Reopening bug 162073, and simply reverting its changes.
Comment 13 David Audel CLA 2007-02-05 12:01:27 EST
Verified for 3.3 M5 using warm-up build I20070205-0009
Comment 14 Olivier Thomann CLA 2007-02-08 11:24:16 EST
*** Bug 173477 has been marked as a duplicate of this bug. ***
Comment 15 Stefan Mücke CLA 2007-02-20 04:12:25 EST
Works fine again in 3.3 M5. Thank you very much!
Comment 16 Olivier Thomann CLA 2007-03-06 15:29:25 EST
*** Bug 176528 has been marked as a duplicate of this bug. ***