Community
Participate
Working Groups
Eclipse Compiler generates synthetic $SWITCH_TABLE$ method whenever switch on enum value is used. The method is being generated in class where switch occurs. So, if there is an aspect with a pointcut at all of the class' methods, generated method is being processed too. I suppose it's not correct behaviour, as $SWITCH_TABLE$ method is some performance tweak, something user don't know about (because didn't write himself), thus it shouldn't be processed. Here is the way to reproduce it: public class HelloWorldEnumSwitch { public static void main(String[] args) { switch(TestEnum.A) { case A: System.out.println("A"); break; case B: System.out.println("B"); } } public static enum TestEnum { A, B; private TestEnum() { } } } @Aspect public class TestAspect { @Around("execution(* *..*.*(..))") public Object beanAnnotatedWithMonitor(ProceedingJoinPoint pjp) throws Throwable { System.out.println(pjp.getSignature().getName()); return pjp.proceed(); } } During execution $SWITCH_TABLE$HelloWorldEnumSwitch$TestEnum will be printed. I made a small pull request with a fix: https://github.com/eclipse/org.aspectj/pull/60 It also contains a test for such behaviour.
With binary weaving also being an option, ought to consider what javac does here too. I see that javac (at least 1.8 that I'm looking at) creates an inner class with a static initializer that does the job. The inner class is marked synthetic, called HelloWorldEnumSwitch$1 Has a single int[] field: $SwitchMap$HelloWorldEnumSwitch$TestEnum; Such a shame the class name didn't indicate the use as a switch table initializer. So the PR will only fix the pure ajc compilation route, not the binary weaving. But I might still integrate it as a step forward, still chewing on it :)
Integrated the PR, thanks for that. But left with failing tests because where the test is has introduced the need to compute stackmaps before the class is loaded which I don't think the old tests needed. working through it.
I moved the test out of weaver and created a formal 195 test for it. all working now. But I haven't addressed the javac scenario, yet.
Wow! Haven't really thought about javac scenario, sorry =) Well, never used it with AspectJ, actually. This problem weaving looks really interesting, I'll try to look through it too :)
Closing this for the work done, we can open another for javac if someone complains about it.