eclipse-aspectj / aspectj

Other
303 stars 86 forks source link

BCException thrown in LazyClassGen displays non-relocated ASM class names #251

Closed kriegaex closed 1 year ago

kriegaex commented 1 year ago

This relates to https://github.com/eclipse-aspectj/aspectj/issues/250#issuecomment-1664867458.

In the error message "Unable to find ASM classes (org.objectweb.asm.ClassReader, org.objectweb.asm.ClassVisitor)", we expect relocated class names like aj.org.objectweb.asm.ClassReader.

The reason for AJ using non-relocated ones is, that the string constant for the exception message is created during compile time, but package relocation takes place later during JAR packaging. I.e., here

https://github.com/eclipse-aspectj/aspectj/blob/db76c175037c10ce21fc8f7fe681162e31082445/weaver/src/main/java/org/aspectj/weaver/bcel/LazyClassGen.java#L755-L761

constants like AsmDetector.CLASS_READER are read before the relocation process moves ASM to package aj and during runtime the correctly relocated constants are not being evaluated at all, because they were inlined during compilation already.

Therefore, we need a workaround to force the Java compiler not to convert the error message to a string constant. Something like AsmDetector.CLASS_READER.replace('Ä', 'Ö') with "Ä" and "Ö" being characters certainly not occurring in those class names, rendering the replace operation a no-op, looks ugly, but should effectively stop the error message to end up in the class constant pool.