From 0bc991544790227ea04309acd3f094ee2dddf48f Mon Sep 17 00:00:00 2001 From: chiba Date: Fri, 22 Jun 2007 11:50:48 +0000 Subject: [PATCH] fixed a bug of CtClassType#releaseClassFiles() git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@391 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- src/main/javassist/expr/Cast.java | 1 + src/main/javassist/expr/Expr.java | 5 +++++ src/main/javassist/expr/FieldAccess.java | 1 + src/main/javassist/expr/Instanceof.java | 1 + src/main/javassist/expr/MethodCall.java | 1 + src/main/javassist/expr/NewArray.java | 1 + src/main/javassist/expr/NewExpr.java | 2 ++ 7 files changed, 12 insertions(+) diff --git a/src/main/javassist/expr/Cast.java b/src/main/javassist/expr/Cast.java index bcce724a..effa8010 100644 --- a/src/main/javassist/expr/Cast.java +++ b/src/main/javassist/expr/Cast.java @@ -87,6 +87,7 @@ public class Cast extends Expr { * @param statement a Java statement. */ public void replace(String statement) throws CannotCompileException { + thisClass.getClassFile(); // to call checkModify(). ConstPool constPool = getConstPool(); int pos = currentPos; int index = iterator.u16bitAt(pos + 1); diff --git a/src/main/javassist/expr/Expr.java b/src/main/javassist/expr/Expr.java index 6d9566f9..e21d148d 100644 --- a/src/main/javassist/expr/Expr.java +++ b/src/main/javassist/expr/Expr.java @@ -247,6 +247,11 @@ public abstract class Expr implements Opcode { } } + // The implementation of replace() should call thisClass.checkModify() + // so that isModify() will return true. Otherwise, thisClass.classfile + // might be released during compilation and the compiler might generate + // bytecode with a wrong copy of ConstPool. + /** * Replaces this expression with the bytecode derived from * the given source text. diff --git a/src/main/javassist/expr/FieldAccess.java b/src/main/javassist/expr/FieldAccess.java index 63d2b458..97f3ce14 100644 --- a/src/main/javassist/expr/FieldAccess.java +++ b/src/main/javassist/expr/FieldAccess.java @@ -147,6 +147,7 @@ public class FieldAccess extends Expr { * @param statement a Java statement. */ public void replace(String statement) throws CannotCompileException { + thisClass.getClassFile(); // to call checkModify(). ConstPool constPool = getConstPool(); int pos = currentPos; int index = iterator.u16bitAt(pos + 1); diff --git a/src/main/javassist/expr/Instanceof.java b/src/main/javassist/expr/Instanceof.java index cdc9ce93..b5de1b97 100644 --- a/src/main/javassist/expr/Instanceof.java +++ b/src/main/javassist/expr/Instanceof.java @@ -90,6 +90,7 @@ public class Instanceof extends Expr { * @param statement a Java statement. */ public void replace(String statement) throws CannotCompileException { + thisClass.getClassFile(); // to call checkModify(). ConstPool constPool = getConstPool(); int pos = currentPos; int index = iterator.u16bitAt(pos + 1); diff --git a/src/main/javassist/expr/MethodCall.java b/src/main/javassist/expr/MethodCall.java index 2a9a891a..63a5bf9a 100644 --- a/src/main/javassist/expr/MethodCall.java +++ b/src/main/javassist/expr/MethodCall.java @@ -176,6 +176,7 @@ public class MethodCall extends Expr { * @param statement a Java statement. */ public void replace(String statement) throws CannotCompileException { + thisClass.getClassFile(); // to call checkModify(). ConstPool constPool = getConstPool(); int pos = currentPos; int index = iterator.u16bitAt(pos + 1); diff --git a/src/main/javassist/expr/NewArray.java b/src/main/javassist/expr/NewArray.java index 44ba80f9..48ebc9f6 100644 --- a/src/main/javassist/expr/NewArray.java +++ b/src/main/javassist/expr/NewArray.java @@ -170,6 +170,7 @@ public class NewArray extends Expr { throws CompileError, NotFoundException, BadBytecode, CannotCompileException { + thisClass.getClassFile(); // to call checkModify(). ConstPool constPool = getConstPool(); int pos = currentPos; CtClass retType; diff --git a/src/main/javassist/expr/NewExpr.java b/src/main/javassist/expr/NewExpr.java index c37a021a..0552ba9e 100644 --- a/src/main/javassist/expr/NewExpr.java +++ b/src/main/javassist/expr/NewExpr.java @@ -160,6 +160,8 @@ public class NewExpr extends Expr { * @param statement a Java statement. */ public void replace(String statement) throws CannotCompileException { + thisClass.getClassFile(); // to call checkModify(). + final int bytecodeSize = 3; int pos = newPos; -- 2.39.5