Bug 325370 - [plan] ITD fields on interfaces marked as private are still woven as public, despite Bug 299552
Summary: [plan] ITD fields on interfaces marked as private are still woven as public, ...
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.6.9   Edit
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 299552
Blocks:
  Show dependency tree
 
Reported: 2010-09-15 11:42 EDT by Steve Ash CLA
Modified: 2014-05-22 21:04 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Steve Ash CLA 2010-09-15 11:42:12 EDT
Build Identifier: 

Reading Bug 299552 which was released with 1.6.9, I was excited to see that I could keep visibility of woven fields _in_ the targets.  I am having a problem right now, because I have some fields that are being woven into targets that are also JAXB @XmlRootElements.  As the woven fields are public, JAXB is picking them up (with the mangled names).  I can't seem to find a way to supress this.  (Annotations on the ITD field, don't seem to make their way into the target, although this seems like a useful feature.  I haven't tried the declare @annotation functionality-- that might be an option.

Anyways if I create an aspect as:

public aspect TestAspect {
    private interface HasAnotherInt {};
    private int HasAnotherInt.anotherInt = 5;
    declare parents: sma.sample.TestTarget implements HasAnotherInt;
}

and a target type:

public class TestTarget {
    private static int thisStaticFieldInTheClass = 84;
    private int thisFieldIsInTheClass = 42;
    
    public static void main(String[] args) {
        System.out.println("There are " + TestTarget.class.getDeclaredFields().length + " fields");
        for (Field f : TestTarget.class.getDeclaredFields())
            System.out.println("--> " + f.getName() + ", " + Modifier.toString(f.getModifiers()));
    }
}

Then I get:

There are 3 fields
--> thisStaticFieldInTheClass, private static
--> thisFieldIsInTheClass, private
--> ajc$interField$sma_sample_TestAspect$sma_sample_TestAspect$HasAnotherInt$anotherInt, public

which I don't expect.  I expected to get three private fields as described in Bug 299552.  I have tried this within Eclipse using the compiler bundled with AJDT, which reports itself as:

Version: 2.1.0.e35x-release-20100630-1500
AspectJ version: 1.6.9.20100629172100

and I've tried it with the command line ajc, which reports itself as:

AspectJ Compiler 1.6.9 (1.6.9 - Built: Monday Jul 5, 2010 at 15:28:35 GMT) - Eclipse Compiler 0.785_R33x, 3.3

Thoughts?

Reproducible: Always

Steps to Reproduce:
Described above via the submitted test case.
Comment 1 Steve Ash CLA 2010-09-15 11:43:43 EDT
If want the actual *.aj and *.java files, I can attach, but the entire code is pasted above
Comment 2 Andrew Clement CLA 2010-09-15 11:57:44 EDT
Hi Steve,

I'm afraid I didn't make it clear under bug 299552 - that was addressing the situation for field itds on classes, not on interfaces.  Interface ITD fields are handled quite differently, as can be seen by the end result being special accessors (get/set) on the interface and the implementation of those accessors (and the field itself) being added to all top most implementors of the interface.  

However, given the existence of the accessors, I should be able to make the visibility change for interface fields quite easily - I'll try to do that under this bug.  Thanks for the testcode, I don't need the sources.
Comment 3 Steve Ash CLA 2010-09-15 12:12:35 EDT
Great! Wow thanks for the quick response! 

As a correction to my original post for anyone that comes across this in the future.  I'm not sure what I was doing wrong before, but the @XmlTransient on an interface field ITD *is* being carried forward to the target *.class file.  I must've not cleaned my project or something, because I tried 10 times yesterday, and the *.class file didn't have an XmlTransient on my ITD field.  I even ran a bamboo build... I don't know. Its working now.

So the @XmlTransient on the field might be an acceptable solution to my JAXB problem (ofc now after I've spent an hour writing transfer objects *shakes head*)

None the less it would be great to get the fields at the "expected" visibility.

Thanks again!
Comment 4 Eben Stewart CLA 2013-02-11 21:42:15 EST
Just as an additional effect of this bug, if a private interface field is defined, as in:

public aspect WeldAspect {
	private String PublicInterface.stringField = "i am aspected";
	public String PublicInterface.getStringField() {
		return stringField ;
	}
}

@SessionScoped
public class SessionBean implements PublicInterface {
	public String getMyString()  {
		return this.getStringField();
	}
}

This will throw an error during Weld CDI bean validation:
"WELD-000075 Normal scoped managed bean implementation class has a public field"

Since 'stringField' is public, Weld will not create a proxy for beans with public fields.

Verified in the Eclipse Class viewer:
  // Field descriptor #36 Ljava/lang/String;
  @org.aspectj.internal.lang.annotation.ajcITD(targetType="weldaspecttest.PublicInterface",
    name="stringField",
    modifiers=(int) 2)
  public java.lang.String stringField;

Environment:
Tomcat 7
Weld 1.1.10
Aspectj 1.7 in Eclipse AJDT 2.2.1.e42x-RELEASE-20120921-1400
Comment 5 Andrew Clement CLA 2013-06-24 11:06:42 EDT
unsetting the target field which is currently set for something already released
Comment 6 Eben Stewart CLA 2014-05-22 21:04:53 EDT
Any update on this?  This is still occurring in 1.8.0.