Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-dev] Declaring an inner anonymous class in an ITD method

Hi,

If AspectJ generated code that caused an IllegalAccessError then that is a bug, please open it.
It should either say 'no you cant do that' at compile time or generate the right code.
A testcase in the bug report would be great :)

cheers,
Andy.

2008/10/15 Simone Gianni <simoneg@xxxxxxxxxx>
Hi all,
I have the following situation. I'm adding new methods to an existing
class using ITDs. These methods are installing some listeners, and as it
is common they use anonymous inner classes, in the form of new
MouseListener() { ... }. AspectJ correctly creates these inner classes
in the package of the destination class. Unfortunately however, these
classes are package protected, and AspectJ generates ITD methods in the
aspect class that call the TargetClass$1.<init>, causing an
IllegalAccessError.

Moving the aspect class to the target package resolves the problem,
cause anonymous inner classes are declared as package protected so they
are accessible as long as the aspect is in the same package.

Is this a bug? I know this is a strange and less than usual situation,
but isn't this the role of the user? put as much fantasy and creativity
as needed to find those usecases the original developers never dreamed
about? :)

If this is a bug, solutions could be :
- Declare anonymous inner classes declared inside an ITD method as
public to avoid this problem. I know this is not what standard javac
does, but will the JVM complain? This could be the simples solution.
- AspectJ correctly creates inner classes in the target package,
couldn't it also generate a "bridging class" in the target package and
wrap calls from the original ITD method (that resides in the aspect
class) to the inner classes via the bridging class?
- In both cases, this situation can be at least reported as a warning or
an error at compile time.

Simone

P.S. Please note that another (tracing) aspect is also matching these
methods and using an around advice. I supposed, since the synthetic
methods that perform the call causing the error were named
aroundBody<number>, that the other aspect was playing a role here.
Anyway, removing the around aspect didn't change the situation. The ITD
methods still reside in the aspect and still call the package protected
<init> of the inner classes declared in the target class package, so
still raising the error.

--
Simone Gianni            CEO Semeru s.r.l.           Apache Committer
MALE human being programming a computer   http://www.simonegianni.it/

_______________________________________________
aspectj-dev mailing list
aspectj-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-dev


Back to the top