From e75c12e0964f27abb798393473913307d24efe61 Mon Sep 17 00:00:00 2001 From: chiba Date: Wed, 6 Jun 2012 14:34:02 +0000 Subject: [PATCH] fixed JASSIST-166 git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@633 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- Readme.html | 3 ++- src/main/javassist/compiler/TypeChecker.java | 3 +++ src/test/javassist/JvstTest4.java | 13 +++++++++++++ src/test/test4/JIRA166.java | 12 ++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/test/test4/JIRA166.java diff --git a/Readme.html b/Readme.html index 450b2ec3..ef74f171 100644 --- a/Readme.html +++ b/Readme.html @@ -283,7 +283,8 @@ see javassist.Dump.

-version 3.17

-version 3.16.1 on March 6, 2012 diff --git a/src/main/javassist/compiler/TypeChecker.java b/src/main/javassist/compiler/TypeChecker.java index fc6a567e..35a8e378 100644 --- a/src/main/javassist/compiler/TypeChecker.java +++ b/src/main/javassist/compiler/TypeChecker.java @@ -899,6 +899,9 @@ public class TypeChecker extends Visitor implements Opcode, TokenId { public void atArrayLength(Expr expr) throws CompileError { expr.oprand1().accept(this); + if (arrayDim == 0) + throw new NoFieldException("length", expr); + exprType = INT; arrayDim = 0; } diff --git a/src/test/javassist/JvstTest4.java b/src/test/javassist/JvstTest4.java index f7fcd968..f7319008 100644 --- a/src/test/javassist/JvstTest4.java +++ b/src/test/javassist/JvstTest4.java @@ -711,4 +711,17 @@ public class JvstTest4 extends JvstTestRoot { assertTrue(javassist.runtime.Desc.getClazz("[Ljava.lang.String;") != null); javassist.runtime.Desc.useContextClassLoader = old; } + + public void testJIRA166() throws Exception { + CtClass cc = sloader.get("test4.JIRA166"); + cc.instrument(new ExprEditor() { + public void edit(FieldAccess fa) throws CannotCompileException { + if (fa.isReader() && fa.getFieldName().equals("length")) + fa.replace("length = self().length + \"!\"; $_ = ($r) this.length.substring(1);"); + } + }); + cc.writeFile(); + Object obj = make(cc.getName()); + assertEquals(1, invoke(obj, "run")); + } } diff --git a/src/test/test4/JIRA166.java b/src/test/test4/JIRA166.java new file mode 100644 index 00000000..bbd46efc --- /dev/null +++ b/src/test/test4/JIRA166.java @@ -0,0 +1,12 @@ +package test4; + +public class JIRA166 { + String length = "jira166"; + JIRA166 self() { return this; } + void print() { System.out.println(length); } + public int run() { + print(); + System.out.println(length); + return 1; + } +} -- 2.39.5