aboutsummaryrefslogtreecommitdiffstats
path: root/weaver
diff options
context:
space:
mode:
authorAlexander Kriegisch <Alexander@Kriegisch.name>2023-08-06 09:12:38 +0700
committerAlexander Kriegisch <Alexander@Kriegisch.name>2023-08-06 09:38:11 +0700
commitd6685f6aef7edc92a14173b45fd62126acd58b28 (patch)
tree8cfa19db6f03759a36a098fb337b5ded83797b0a /weaver
parentf44dc75e6b0e9a80b41dce7b43fa1a393a4a2adb (diff)
downloadaspectj-d6685f6aef7edc92a14173b45fd62126acd58b28.tar.gz
aspectj-d6685f6aef7edc92a14173b45fd62126acd58b28.zip
Improve error message in LazyClassGen.getJavaClassBytesIncludingReweavable
No longer report "Unable to find ASM classes", if simply an ASM processing error occurred. In that case, report "Error processing class file". Relates to #250. Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
Diffstat (limited to 'weaver')
-rw-r--r--weaver/src/main/java/org/aspectj/weaver/bcel/LazyClassGen.java22
-rw-r--r--weaver/src/main/java/org/aspectj/weaver/bcel/asm/AsmDetector.java4
-rw-r--r--weaver/src/main/java/org/aspectj/weaver/bcel/asm/StackMapAdder.java2
3 files changed, 17 insertions, 11 deletions
diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/LazyClassGen.java b/weaver/src/main/java/org/aspectj/weaver/bcel/LazyClassGen.java
index 61ebfb7cf..0a21db2c9 100644
--- a/weaver/src/main/java/org/aspectj/weaver/bcel/LazyClassGen.java
+++ b/weaver/src/main/java/org/aspectj/weaver/bcel/LazyClassGen.java
@@ -753,14 +753,20 @@ public final class LazyClassGen {
// are required (unless turning off the verifier)
if ((myGen.getMajor() == Constants.MAJOR_1_6 && world.shouldGenerateStackMaps()) || myGen.getMajor() > Constants.MAJOR_1_6) {
if (!AsmDetector.isAsmAround) {
- // Fix https://github.com/eclipse-aspectj/aspectj/issues/251, using "replace('Ä', 'Ö')" to avoid non-relocated
- // class names to be embedded into the error message during compile time, making it end up in the class constant
- // pool unwantedly, as this clashes with post-compile ASM package relocation.
- final String errorMessage = "Unable to find ASM classes (" +
- AsmDetector.CLASS_READER.replace('Ä', 'Ö') + ", " + AsmDetector.CLASS_VISITOR.replace('Ä', 'Ö') + ") " +
- "for stackmap generation. Stackmap generation for woven code is required to avoid verify errors " +
- "on a Java 1.7 or higher runtime.";
- throw new BCException(errorMessage, AsmDetector.reasonAsmIsMissing);
+ if (
+ AsmDetector.rootCause instanceof ClassNotFoundException ||
+ AsmDetector.rootCause instanceof NoClassDefFoundError
+ ) {
+ // Fix https://github.com/eclipse-aspectj/aspectj/issues/251, using "replace('Ä', 'Ö')" to avoid
+ // non-relocated class names to be embedded into the error message during compile time, making it end up in
+ // the class constant pool unwantedly, as this clashes with post-compile ASM package relocation.
+ String errorMessage = "Unable to find ASM classes (" +
+ AsmDetector.CLASS_READER.replace('Ä', 'Ö') + ", " + AsmDetector.CLASS_VISITOR.replace('Ä', 'Ö') + ") " +
+ "for stackmap generation. Stackmap generation for woven code is required to avoid verify errors " +
+ "on a Java 1.7 or higher runtime.";
+ throw new BCException(errorMessage, AsmDetector.rootCause);
+ }
+ throw new BCException("Error processing class file", AsmDetector.rootCause);
}
wovenClassFileData = StackMapAdder.addStackMaps(world, myGen.getClassName(), wovenClassFileData);
}
diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/asm/AsmDetector.java b/weaver/src/main/java/org/aspectj/weaver/bcel/asm/AsmDetector.java
index a12a5617e..09177511c 100644
--- a/weaver/src/main/java/org/aspectj/weaver/bcel/asm/AsmDetector.java
+++ b/weaver/src/main/java/org/aspectj/weaver/bcel/asm/AsmDetector.java
@@ -20,7 +20,7 @@ public class AsmDetector {
public static final String CLASS_READER = "org.objectweb.asm.ClassReader";
public static final String CLASS_VISITOR = "org.objectweb.asm.ClassVisitor";
public static boolean isAsmAround;
- public static Throwable reasonAsmIsMissing;
+ public static Throwable rootCause;
static {
try {
@@ -30,7 +30,7 @@ public class AsmDetector {
isAsmAround = true;
} catch (Exception e) {
isAsmAround = false;
- reasonAsmIsMissing = e;
+ rootCause = e;
}
//System.out.println(isAsmAround ? "ASM detected" : "No ASM found");
}
diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/asm/StackMapAdder.java b/weaver/src/main/java/org/aspectj/weaver/bcel/asm/StackMapAdder.java
index ae22ed067..1c742cd08 100644
--- a/weaver/src/main/java/org/aspectj/weaver/bcel/asm/StackMapAdder.java
+++ b/weaver/src/main/java/org/aspectj/weaver/bcel/asm/StackMapAdder.java
@@ -49,7 +49,7 @@ public class StackMapAdder {
System.err.println("AspectJ Internal Error: unable to add stackmap attributes to class '"+classname+"'. " + t.getMessage());
t.printStackTrace();
AsmDetector.isAsmAround = false;
- AsmDetector.reasonAsmIsMissing = t;
+ AsmDetector.rootCause = t;
return data;
}
}