From 2b3afd3a5dd8dc0e2c4733b10b1661d170356c19 Mon Sep 17 00:00:00 2001 From: adrian Date: Mon, 6 Feb 2006 10:02:34 +0000 Subject: [PATCH] Compacting/clone has a problem when the method index is zero. This looks like an inner class trying to describe its outer class rather than a method. git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@242 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- .../bytecode/EnclosingMethodAttribute.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/javassist/bytecode/EnclosingMethodAttribute.java b/src/main/javassist/bytecode/EnclosingMethodAttribute.java index 53002951..1efcb82c 100644 --- a/src/main/javassist/bytecode/EnclosingMethodAttribute.java +++ b/src/main/javassist/bytecode/EnclosingMethodAttribute.java @@ -55,6 +55,24 @@ public class EnclosingMethodAttribute extends AttributeInfo { set(bvalue); } + /** + * Constructs an EnclosingMethod attribute. + * + * @param cp a constant pool table. + * @param className the name of the innermost enclosing class. + */ + public EnclosingMethodAttribute(ConstPool cp, String className) { + super(cp, tag); + int ci = cp.addClassInfo(className); + int ni = 0; + byte[] bvalue = new byte[4]; + bvalue[0] = (byte)(ci >>> 8); + bvalue[1] = (byte)ci; + bvalue[2] = (byte)(ni >>> 8); + bvalue[3] = (byte)ni; + set(bvalue); + } + /** * Returns the value of class_index. */ @@ -105,6 +123,8 @@ public class EnclosingMethodAttribute extends AttributeInfo { * class names. */ public AttributeInfo copy(ConstPool newCp, Map classnames) { + if (methodIndex() == 0) + return new EnclosingMethodAttribute(newCp, className()); return new EnclosingMethodAttribute(newCp, className(), methodName(), methodDescriptor()); } -- 2.39.5