Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Unable to access new ITD in a successfully woven rt.jar

Hi.

As you could see from your javap output, the field has a mangled name
on the target.  This means you can't see it from pure java as 'test' -
if you want to access the field on File like that (from pure java) you
would need to use
'f.ajc$interField$mytest_weavert$mytest_ClassWC$test'.

Let me give some background:

What you actually asked for in your aspect is a field called test on
your interface.  Java interfaces don't allow (non-static) fields - and
so with javap you are seeing how AspectJ implements that feature.  The
field cannot 'live' in the interface - so it is hosted in the top most
implementing types of the interface.  In your case that is Field - so
we see the mangled field name there.  It is mangled to avoid any
problems that might occur if the top most implementors already had a
public field called test.

If you were using ajc to compile your code referencing test, you would
see it, because ajc understands how it has had to implement interface
fields.

Or alternatively to using ajc, if you are weaving rt.jar like that -
why not just do the ITD directly onto File?

 public aspect weavert {
    public String File.test;
  }

(And Michael is right about the /p to ensure your woven version is
picked up first)

Andy

On 1 February 2010 22:17, H G <botakh15@xxxxxxxxx> wrote:
>
> Hi all,
>
> I'm adding ITD to rt.jar and so far I've weaved rt.jar successfully.
> But, for some reason I'm not able to access the new ITD from my
> woven-rt.jar.
> I've done my homework (6-hour googling to find some hints), but no luck.
> So, I'd deeply appreciate if I can get any help here.
>
> Here's my simple aspect, where I just want to add "String test" to the
> claas java.io.File:
>
>   package mytest;
>   public interface ClassWC { };
>   public aspect weavert {
>     declare parents: File implements ClassWC;
>     public String ClassWC.test;
>   }
>
> I compiled that, and ran javap on my woven-rt.jar:
>
>   javap java.io.File -bootclasspath woven-rt.jar
>
> I get this:
>
>   public class java.io.File
>     extends java.lang.Object
>     implements java.io.Serializable,
>                java.lang.Comparable,
>                mytest.ClassWC {
>     ...
>     public java.lang.String
> ajc$interField$mytest_weavert$mytest_ClassWC$test;
>     ...
>  }
>
> So up to this point, everything seems okay.
> Now, here's my simple test program (Main.java) where I just want to
> see if File.test is accessible or not.
>
>   main() {
>     File f = new File("file.txt");
>     String test = f.test;
>   }
>
> I compiled that:
>
>   javac -Xbootclasspath:woven-rt.jar Main.java
>
> I get this following error:
>
>   Main.java:21: cannot find symbol
>   symbol  : variable test
>   location: class java.io.File
>             String test = f.test;
>
>
> I totally have no clue why I cannot access File.test.
> I try to make the original rt.jar unreadable (chmod 000)
> to verify that javac is not reading the original rt.jar.
> It turns out I get this error:
>
>   java/lang/ClassNotFoundException: error in opening JAR file <Permission
> denied>
>
>
> I believe I use bootclasspath properly.
> Please help me point where I did wrong.
> Thanks again for your time!
>
> Harry
>
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>


Back to the top