Bug 124810 - Strange field binding has inconsistent hierarchy
Summary: Strange field binding has inconsistent hierarchy
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2 M5   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-01-22 13:18 EST by Dirk Baeumer CLA
Modified: 2006-02-14 09:05 EST (History)
2 users (show)

See Also:


Attachments
Proposed patch (7.51 KB, patch)
2006-01-26 17:21 EST, Olivier Thomann CLA
no flags Details | Diff
Proposed patch (7.52 KB, patch)
2006-01-26 17:23 EST, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dirk Baeumer CLA 2006-01-22 13:18:42 EST
Head 2006/01/10

public class TestImpl implements p.Test {
	
	private String town;
	 
	public String getTown() {
		return town;
	}
	  
	public void setTown(String town) {
		this.town = town;
	}
}

Inspect the type binding retrieved from the type declaration and look at the declared fields. Observe there is a field declaration called: 

1: TestImpl.has inconsistent hierarchy

The field is especially problematic for APT.
Comment 1 Philipe Mulet CLA 2006-01-23 03:55:47 EST
Kent: did we make this field be synthetic ? We should hide it.
Comment 2 Kent Johnson CLA 2006-01-23 10:09:23 EST
We added the field so we can detect the case of:

class A extends Missing {} // we create a problem type of class A {}

becoming:

class A {}

So we need this field to tell us that A has changed structurally, because its superclass did not appear to change.
Comment 3 Kent Johnson CLA 2006-01-23 10:10:18 EST
Can you think of another way we can take of this case ?
Comment 4 Philipe Mulet CLA 2006-01-24 06:18:57 EST
It could be in the classfile, since you need it, but we should ensure the field artifact is correctly hidden from our tools (like we do hide synthetic constructor arguments for innerclasses).
Comment 5 Kent Johnson CLA 2006-01-25 13:39:40 EST
We could remove the field if:

We add the attribute 'AttributeNameConstants.SuperclassMissing' to any .class file with a missing superclass & then detect that this attribute does not exist on the newly created copy and report a structural change.

We'll also need a new tagBit 'SuperclassMissing' to set on sourceTypeBindings in ClassScope.connectSuperclass(), so we can tell that a type should have the new attribute.

Make sense?
Comment 6 Olivier Thomann CLA 2006-01-26 15:44:42 EST
The new attribute could be used to set the tagBits SuperclassMissing when reading the .class file.
Then the structural change could be detected by checking the tagbits.
It is trivial to add a new attribute. Simply let me know you want to go on this path.
Comment 7 Kent Johnson CLA 2006-01-26 16:34:45 EST
We just need the new attribute, not the tagBit.

We want to replace this code in ClassScope.buildFields()

boolean hierarchyIsInconsistent =
  referenceContext.binding.isHierarchyInconsistent();
if (referenceContext.fields == null) {
  if (hierarchyIsInconsistent) { // 72468
    referenceContext.binding.fields = new FieldBinding[1];
    referenceContext.binding.fields[0] =
      new FieldBinding(IncompleteHierarchy, TypeBinding.INT,
        ClassFileConstants.AccPrivate, referenceContext.binding, null);

With the attribute in the class file, then compare it in the ClassFileReader.
Comment 8 Philipe Mulet CLA 2006-01-26 16:36:15 EST
+1 for attribute. As per discussion with Kent, we do not need extra tagbit.
Comment 9 Olivier Thomann CLA 2006-01-26 17:21:44 EST
Created attachment 33672 [details]
Proposed patch

Kent,

This patch takes care of the creation of the new attribute. The classfile reader is updated to reflect the presence of this attribute in its access flags.
I cleaned the code that was using the field binding.
Please double check the patch and you can release. I passed all builder tests with it.
Comment 10 Olivier Thomann CLA 2006-01-26 17:23:38 EST
Created attachment 33673 [details]
Proposed patch

Previous patch left an unused local behind. This is cleaned with this patch.
Comment 11 Kent Johnson CLA 2006-01-27 11:47:06 EST
Looks good - DependencyTests still pass.

Released patch to remove the field and use an attribute in the class file instead.
Comment 12 David Audel CLA 2006-02-14 09:05:58 EST
Verified for 3.2 M5 using build I20060214-0010