unfortunately not, still living with the same problem...
unfortunately not, still living with the same problem...
Even my vacation got over but this problems don't seems to going away! :rolleyes:
This is a problem seems to be a maven 2 configuration as I could have my code working when executed from eclipse!
Also i was debugging (on the complied code by Maven, complied code through eclipse works fine) using Spring code and here's my findings.
This is my Advise Code
public class NewOpsAfterThrowsAdvise {
public void afterThrowing(Throwable ex) {
List <String>params = new ArrayList<String>();
// Do something will all arguments
System.out.print("Exception caught in the interceptor...");
System.out.println(ex.getClass().getSimpleName());
//Log the exception.
//unwrap the exception
if(ex instanceof RuntimeException) {
String issueCode;
if(ex instanceof NewOpsRuntimeException){
issueCode = ((NewOpsRuntimeException)ex).getIssues().get(0).ge tCode();
}else{
issueCode = ex.getMessage();
}
if (ex.getCause() == null) {
params.add( ex.getClass().getSimpleName());
} else {
while (ex.getCause() != null) {
ex = ex.getCause();
}
params.add(ex.getMessage());
params.add(ex.getCause().getClass().getSimpleName( ));
}
throw new NewOpsRuntimeException(issueCode, params,ex);
}
}
- In the class LocalVariableTableParameterNameDiscoverer.java
private ParameterNameDiscoveringVisitor visitMethod(Method method) throws IOException {
ClassReader reader = new ClassReader(method.getDeclaringClass().getName());
FindMethodParamNamesClassVisitor classVisitor = new FindMethodParamNamesClassVisitor(method);
reader.accept(classVisitor,false);
return classVisitor;
}
The Class visitor that is returned has parameterNames as "issueCode" which is a local variable in my advise code, but the correct value for parameters should be "ex"
Any thoughts what's going wrong??
tried a tricky thing, In the maven generated jar, i replaced my advise class file with eclipse compiled advise class file
and it worked! thus driving to point my figures towards my Pom file......
for Maven to compile AOP, Do i need to have any special plug-ins installed?
Regards,
Ravi
If I remove all the local variables from my advise method
then my advise works even when compiled through maven.
But haven't understood the relation between Maven compile code and Local variables in advise method.
any thoughts what's the missing link?
further debugging the spring code in LocalVariableTableParameterNameDiscoverer.java for the method
public void visitLocalVariable(String name, String description, String signature, Label start, Label end, int index) {
this.hasLVTInfo = true;
if (!this.isStatic) {
index--;
}
if (index >= 0 && (this.parameterNames.size() < this.numParameters)) {
this.parameterNames.add(name);
}
}
this method is invoked multiple times, If advise code compiled through Maven then "name" attribute of the method is invoked with the following values sequentially
- issueCode (local variable name)
- ex (parameter binding)
the same if advise code is compiled through my eclipse then the "name" attribute receives the following values sequentially
- this
- ex
- issueCode
My question is, why does the order of the method invocation change when compiled through Eclipse or Maven?
any pointers would be great help!!
any helping hands for my problem?
I'm I the only one stuck with this stupid problem!?
Exact same situation here...
- Compiling in Eclipse works
- Compiling using maven2 fails
- Replacing the Advice class file that Maven built with the one Eclipse built allows the thing to work.
- Removing all local variables also allows it to work when built by Maven2
My situation is exactly the same as the OP, and I can't think of anything else to post, so if you want more details, just look above in this post :)
Anybody have any ideas?
I think I know what is going on...
Compile your aspects using either -g or -g:vars flag. When you use any context (this, target, argument, thrown exception etc.), Spring's AOP mechanism needs to figure out the advice argument names. Without -g or -g:vars, javac simply removes all method argument names (and local variables).
Please try it and report your experience.
-Ramnivas
I've already tried that :) I've forked the maven2 compiler to assure me that I am using an up to date javac. I have tried using -g and -g:var flags as seen in the config below... Still no go. Technically you should not need to set the debug flag anyway because it is set by default as part of the maven-compiler-plugin.
ramnivas: Did you actually get this working? or did you just abandon it, or remove all local variables?
Code:<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<fork>true</fork>
<source>1.5</source>
<target>1.5</target>
<executable>C:\Javatool\java\jdk1.6.0\bin\javac</executable>
<compilerArgument>-g</compilerArgument>
</configuration>
</plugin>
I haven't used Spring-AspectJ-AOP/Maven combination (used Spring/AspectJ/Maven combination, but that is a different story). I have, however, used Spring-AspectJ-AOP/Ant combination. I have seen exactly the same problem as described (and there are many other threads with the same problem and solution). In each cases, adding -g/-g:vars solved the problem.
I notice that you are using Java6 compiler (granted, you are using -source 5). I do wonder if that is somehow playing a role. Can you try using Java5 compiler? There are known issues with using AspectJ along with Java 6.
-Ramnivas
Still no luck with using the jdk5 compiler with -g :(
HOWEVER, I did make a very interesting discovery. I seem to be able to have local variables as long as they are not of type "Object". For example...
... Just does not work... All my other locals seem to be fine?!?!?!?! Heck, even...Code:Object arg = call.getArgs()[paramIndex];
... makes it fail :( I think I can work around the issue now, but this certainly is disturbing. If I have time I will do a very basic maven2 project that duplicates the issue, and post it for others to play with. If anyone else has experienced such a behavior, please let me know.Code:Object arg=null