Bug 114343 - [generics] field-get problems when generic field is used.
Summary: [generics] field-get problems when generic field is used.
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: DEVELOPMENT   Edit
Hardware: PC Linux
: P2 critical (vote)
Target Milestone: 1.5.0RC1   Edit
Assignee: Andrew Clement CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-10-31 07:22 EST by Misha Kantarovich CLA
Modified: 2005-11-24 03:31 EST (History)
0 users

See Also:


Attachments
Test case (8.58 KB, application/octet-stream)
2005-11-17 09:57 EST, Misha Kantarovich CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Misha Kantarovich CLA 2005-10-31 07:22:47 EST
Hi guys!

I've downloaded DEVELOPMENT-20051029200407.

There is some issue that I think is still open.
Take a look at the example:

Java Code:
----------

public class Test1 {

	Set<Integer> intsSet;

	public Set<Integer> foo() {
		return intsSet;
	}
}

public class Test2 {

	Set<Double> dSet;

	public Set<Double> foo() {
		return dSet;
	}
}

Aspect:
-------

public privileged aspect TestAspect {

    pointcut gettingMemberCollection(Test t) :
                target(t) &&
                get(!public Set<Number+> com.*.*) &&
                !within(TestAspect);

    Set around(Test t) : gettingMemberCollection(t)  {
        Set s =  proceed(t);
        return s;
    }
}

As you can see, I would like to replace access to member Set of something which 
derives from Number. But the problem is that around advice is stricted to 
return exact type of the member, and I'm getting the same error as earlier.

incompatible return type applying to field-get(java.util.Set 
com.mprv.secsph.Test.intsSet)

incompatible return type applying to field-get(java.util.Set 
com.mprv.secsph.Test.dSet)

In the M2 I just declared the advice this way and it worked fine.

May be now, you should allow to declare the advice this way:

    Set<? extends Number> around(Test t) : gettingMemberCollection(t) {
        Set s = proceed(t);
        return s;
    }

Thanks!
Misha.
Comment 1 Andrew Clement CLA 2005-10-31 07:38:27 EST
interesting.  it is a slight variation from the previous problem posted. marking
RC1.
Comment 2 Andrew Clement CLA 2005-11-01 06:23:01 EST
Fix checked in.  We will allow the case where you use 'Set' as the around()
advice return value but you will get an unchecked conversion warning, if you
want to hide the conversion warning, use -Xlint to suppress it or this
annotation on the advice

@org.aspectj.lang.annotation.SuppressAjWarnings("uncheckedAdviceConversion")

Waiting on build before closing.
Comment 3 Misha Kantarovich CLA 2005-11-01 06:38:00 EST
Thanks A LOT!

I'll get the build as soon as it's ready.
Comment 4 Andrew Clement CLA 2005-11-01 08:17:48 EST
fix available from download page.  thanks for the clear bug report and test case.
Comment 5 Misha Kantarovich CLA 2005-11-02 14:13:20 EST
Hi!

Another issue ... :)

Here is the example:

Java Code:
----------

public class Test<T> {

	Set<T> set;

	public <T> T[] toArray(T[] a) {
		return set.toArray(a);
	}
}

public class TTT {
	public void foo() {
		Test<Integer> mt = new Test<Integer>();
		Integer[] arr = mt.toArray(new Integer[]{});
	}
}

Aspect:
-------

public privileged aspect TestAspect {

      pointcut TestToArray(Test mt) :
                target(mt) &&
                !within(TestAspect);


    Object[] around(Test mt, Object[] objs) :
            TestToArray(mt) &&
            args(objs) &&
            execution(Object[] com.Test.toArray(Object[])) {

        objs = proceed(mt, objs);
        return objs;
    }
}

Errors:
-------
TestAspect.aj:19::381 incompatible return type applying to method-execution
(java.lang.Object[] com.mprv.secsph.Test.toArray(java.lang.Object[]))

Test.java:19:0::0 incompatible return type applying to method-execution
(java.lang.Object[] com.mprv.secsph.Test.toArray(java.lang.Object[]))


As you see, I'm trying to apply around advice to generic version of "toArray" 
method. I think it's impossible for now to do so ...

P.S. THANKS A LOT for your fast responses and almost immediate bug fixes!!!
Comment 6 Andrew Clement CLA 2005-11-02 14:32:51 EST
sigh...
Comment 7 Andrew Clement CLA 2005-11-02 15:35:03 EST
eventually we'll get to a point where you try something and it works :)  I'll
look at this bug tomorrow morning.
Comment 8 Misha Kantarovich CLA 2005-11-03 03:19:45 EST
Don't misunderstand me, I've tried a lot of things in AspectJ that already 
work :) - we have developed for a 6 months with M2 version and it was great. 

Just a new generics stuff is still causing problems, but this is what 
Milestones are made for :)

I think you are doing a great job!

Thanks!
Comment 9 Andrew Clement CLA 2005-11-03 05:31:16 EST
Fix for latest case committed.  I'm going to experiment a little bit with it
though - I suspect if the bounds of the type variable aren't Object then we'll
blow up...
Comment 10 Andrew Clement CLA 2005-11-03 06:05:56 EST
Ok, tried my case and *it worked* (shock horror).  So i'll close this bug again
when the build comes through :)  thanks for the simple testcase each time.
Comment 11 Andrew Clement CLA 2005-11-03 08:16:44 EST
*boing* it bounces closed again - build is available with latest fix in.
Comment 12 Misha Kantarovich CLA 2005-11-17 03:15:10 EST
Hi,

It seems that those "field-get problems" were not fixed in aspectjweaver.jar.

When I compile my code I only get warnings for "unchecked conversion" (like 
expected). But when I've tried to enable load time weaving, I've got the same 
errors like in my first post here.

Thanks!
Comment 13 Andrew Clement CLA 2005-11-17 03:30:16 EST
As it fails LTW, it probably fails binary weaving - I'll try it out.
Comment 14 Andrew Clement CLA 2005-11-17 08:01:24 EST
seems to work for me either binary weaving or LTW - so I need more information,
I must be doing something different to you.  I'm using the program almost as
described in the original post on this bug report - except my Test1 and Test2
are subclasses of a simple Test type (required by the pointcut definition...)

Or are you referring to the program in comment #5?

And when you say 'enabled load time weaving' - how are you doing that? command
line? in AJDT?

I'm confused because exactly the same logic is used to weave in either case - so
I can't currently see how it can work in one case and not another, hmmm.
Comment 15 Misha Kantarovich CLA 2005-11-17 08:20:17 EST
Hi,

I'm referring to the FIRST post - not comment #5.
I'm enabling LTW by passing: 
-javaagent:/my_path/aspectjweaver.jar 
to JVM.

I have the development build from November 3. When I look at the content of the 
aspectjweaver.jar I can see that most of the classes are created at Nov 3, but 
some of them are from Oct 17. May be aspectjweaver.jar is not up-to-date?

Thanks!
Comment 16 Misha Kantarovich CLA 2005-11-17 08:31:34 EST
October 10, not 17
Comment 17 Andrew Clement CLA 2005-11-17 09:11:00 EST
Some of the jar contents come from other jars - if those weren't rebuilt then
they'll still have the old dates in aspectjweaver.jar (e.g.
org/aspectj/apache/bcel/*).  I don't think thats a problem here as the fix was
in org/aspectj/weaver/Advice which doesn't come from a jar.

two things:

1. Can you try on a more up to date dev build?  3rd Nov is a bit old... 
although I don't know that this will help considering the fix was committed on
the 1st Nov.

2. Can I ask how you are building the parts of the application prior to load
time weaving?
Comment 18 Misha Kantarovich CLA 2005-11-17 09:57:12 EST
Created attachment 30140 [details]
Test case
Comment 19 Misha Kantarovich CLA 2005-11-17 10:00:07 EST
Hi Andy,

I've attached the IntelliJ Idea's project. Unfortunately bugzilla didn't allow
me to attach more than 10MB, so you will have to put aspectj libs in the
project's lib directory.

Run it. You will receive the errors. 
For build information, you can look at the build.xml

If you have questions, I'm here :)
Comment 20 Misha Kantarovich CLA 2005-11-22 05:21:39 EST
Guys? What about this bug? 
Comment 21 Andrew Clement CLA 2005-11-22 05:44:25 EST
You havent been forgotten - I've just a mountain of bugs to get through and they are all serious.  Did you try a more recent dev build, per my comment #17.  If you could unpick your build.xml to explain how the parts of the application build prior to load time weaving, that will help me too.  I don't use intellij so haven't looked at the appended tar.gz yet.
Comment 22 Andrew Clement CLA 2005-11-23 09:31:40 EST
I'm trying to recreate this problem.

I've installed an up to date AspectJ in c:\aspectj1.5.0-dev

Then I type 'ant build' then 'ant build-aspects' (the latter of which gives me warnings I can ignore about advice not matching)

I then try and run it from the resultant classes folder:

java -javaagent:c:\aspectj1.5.0-dev\lib\aspectjweaver.jar com.mprv.secsph.Test

and it just blows up with a BCException.

what am i doing wrong such that I don't see the failure you see?

this is what I get:

warning Register definition failed -- (BCException) malformed org.aspectj.weaver.PointcutDeclaration attribute java.io.EOFExceptio
n

malformed org.aspectj.weaver.PointcutDeclaration attribute java.io.EOFException

org.aspectj.weaver.BCException: malformed org.aspectj.weaver.PointcutDeclaration attribute java.io.EOFException

        at org.aspectj.weaver.AjAttribute.read(AjAttribute.java:123)
        at org.aspectj.weaver.bcel.BcelAttributes.readAjAttributes(BcelAttributes.java:59)
        at org.aspectj.weaver.bcel.BcelObjectType.unpackAspectAttributes(BcelObjectType.java:270)
        at org.aspectj.weaver.bcel.BcelObjectType.<init>(BcelObjectType.java:131)
        at org.aspectj.weaver.bcel.BcelWorld.makeBcelObjectType(BcelWorld.java:255)
        at org.aspectj.weaver.bcel.BcelWorld.resolveDelegate(BcelWorld.java:250)
        at org.aspectj.weaver.World.resolveToReferenceType(World.java:296)


Comment 23 Misha Kantarovich CLA 2005-11-23 12:00:02 EST
Hi,

Sorry for the late response. Tonns of work ... :)
Are you still getting this exception?

I'm going to try the latest build now with this testcase.
Comment 24 Misha Kantarovich CLA 2005-11-23 12:16:52 EST
Hi,

I've runned the testcase with the latest (today's Nov 23 build) build and it worked!

I've rechecked it with Nov 3 build, and it didn't work!

Did you do something? :-)

Anyway, thanks a lot!
Comment 25 Andrew Clement CLA 2005-11-23 12:26:30 EST
Thanks for trying it out.  I haven't knowingly done anything to affect this test but we have fixed quite a few bugs in the last few days all over the place.  

So shall I close it again for now? :)  Feel free to reopen if you encounter this problem again.
Comment 26 Misha Kantarovich CLA 2005-11-23 13:48:17 EST
Hi Andy,

Thanks for the help!

I think now this bug can be closed :-)

But there is another issue. Take a look at this post (and topic) - you will know what I'm talking about. 

http://dev.eclipse.org/mhonarc/lists/aspectj-dev/msg01869.html

My problem is that I'm working with Hibernate (3.0.5, cglib 2.1) and LTW seems to cause exceptions in generated code.

Is this issue will be solved in 1.5, or should I leave LTW for a while?

Thanks!
Misha.
Comment 27 Andrew Clement CLA 2005-11-24 03:31:47 EST
Closing as fixed.

On the other comments... I remember that long debate about attributes and annotations.  We have no plans to move to annotations for everything during 1.5.0 - we're going to look at it again for 1.5.1.  Out of interest, how does it manifest as failing for you?  

The problem we were getting at in the annotation/attribute discussion was that ASM discards attributes it doesn't understand - so it discards the attributes AspectJ adds that tells the weaver what to do.  We are thinking about what the right solution is  .... maybe a plugin for ASM that would allow us to define whats allowed through ... maybe we move to annotations, but that isn't a small piece of work we can fit into 1.5.0 now.