From ea734d7e5d9b54415d049699494fa095c324daf9 Mon Sep 17 00:00:00 2001 From: Andy Clement Date: Mon, 31 Jan 2022 15:42:44 -0800 Subject: [PATCH] Try to improve error reporting when Asm access issues --- .../src/main/java/org/aspectj/weaver/bcel/LazyClassGen.java | 4 ++-- .../main/java/org/aspectj/weaver/bcel/asm/AsmDetector.java | 2 ++ .../main/java/org/aspectj/weaver/bcel/asm/StackMapAdder.java | 5 +++-- 3 files changed, 7 insertions(+), 4 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 90a8dadb2..9155b4ba0 100644 --- a/weaver/src/main/java/org/aspectj/weaver/bcel/LazyClassGen.java +++ b/weaver/src/main/java/org/aspectj/weaver/bcel/LazyClassGen.java @@ -757,10 +757,10 @@ public final class LazyClassGen { throw new BCException( "Unable to find ASM classes (" + AsmDetector.CLASS_READER + ", " + AsmDetector.CLASS_VISITOR + ") " + "for stackmap generation. Stackmap generation for woven code is required to avoid verify errors " + - "on a Java 1.7 or higher runtime." + "on a Java 1.7 or higher runtime.", AsmDetector.reasonAsmIsMissing ); } - wovenClassFileData = StackMapAdder.addStackMaps(world, wovenClassFileData); + wovenClassFileData = StackMapAdder.addStackMaps(world, myGen.getClassName(), wovenClassFileData); } WeaverStateInfo wsi = myType.getWeaverState();// getOrCreateWeaverStateInfo(); 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 86571a0c7..a12a5617e 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,6 +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; static { try { @@ -29,6 +30,7 @@ public class AsmDetector { isAsmAround = true; } catch (Exception e) { isAsmAround = false; + reasonAsmIsMissing = 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 2610174df..ae22ed067 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 @@ -37,7 +37,7 @@ import org.objectweb.asm.Opcodes; */ public class StackMapAdder { - public static byte[] addStackMaps(World world, byte[] data) { + public static byte[] addStackMaps(World world, String classname, byte[] data) { try { ClassReader cr = new ClassReader(data); ClassWriter cw = new AspectJConnectClassWriter(cr, world); @@ -46,9 +46,10 @@ public class StackMapAdder { return cw.toByteArray(); } catch (Throwable t) { // If in here fixing an error about version, change the ASMX in class above! - System.err.println("AspectJ Internal Error: unable to add stackmap attributes. " + t.getMessage()); + System.err.println("AspectJ Internal Error: unable to add stackmap attributes to class '"+classname+"'. " + t.getMessage()); t.printStackTrace(); AsmDetector.isAsmAround = false; + AsmDetector.reasonAsmIsMissing = t; return data; } } -- 2.39.5