Project: AspectJ
Bug 151938 Handle Duplicate -javaagent entries more gracefully
Reported: 2006-07-26 19:33:29 | Status: resolved fixed

If you start a java 5 VM with AspectJ's load-time weaver specified more than once using the -javaagent flag, if there is an aop.xml file defined, it chokes badly: it tries to reweave the woven AspectJ code and emits massive amounts of bytecode. It would be better if AspectJ detected that it was specified more than once and gave a warning then disabled all but one of the agents. Failing that, it would be better to fail and give an error message than emit the bytecode. This issue came up for our automated installer, which adds a -javaagent flag to VM startup commands. If the script is wrapped twice, it can generate a duplicate. We are making our scripts more intelligent to avoid this issue, but we are probably not the only people who will hit this issue (e.g., if someone manually edits both setclasspath.bat and catalina.bat to add the flag for a Tomcat instance...)

Files changed in fix:
loadtime5/java5-src/org/aspectj/weaver/loadtime/Agent.java tests/java5/ataspectj/HelloWorld.java tests/java5/ataspectj/MessageHandler.java tests/src/org/aspectj/systemtest/ajc153/Ajc153Tests.java