aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchibash <chiba@javassist.org>2019-12-24 01:02:05 +0900
committerchibash <chiba@javassist.org>2019-12-24 01:02:05 +0900
commit150709141ca5cafa0be64638bbb724aa9879a15d (patch)
tree7bbb0123348e24f1d9b7393d452e509c5fcd6559
parentafe124ffa5794c881c212fb1ebec51a554d0e332 (diff)
downloadjavassist-150709141ca5cafa0be64638bbb724aa9879a15d.tar.gz
javassist-150709141ca5cafa0be64638bbb724aa9879a15d.zip
fixes a bug involuved in Pull Request #294
-rw-r--r--Readme.html2
-rw-r--r--javassist.jarbin771271 -> 772783 bytes
-rw-r--r--src/main/javassist/compiler/MemberCodeGen.java4
-rw-r--r--src/main/javassist/compiler/Parser.java2
-rw-r--r--src/main/javassist/compiler/ast/ArrayInit.java17
-rw-r--r--src/test/javassist/JvstTest5.java16
6 files changed, 37 insertions, 4 deletions
diff --git a/Readme.html b/Readme.html
index fe9908d4..f9d62a27 100644
--- a/Readme.html
+++ b/Readme.html
@@ -283,7 +283,7 @@ see javassist.Dump.
<p>-version 3.27
<ul>
- <li>GitHub Issue #271 (PR #279), #280 (PR #281), and #282.
+ <li>GitHub Issue #271 (PR #279), #280 (PR #281), #282, and PR #294.
</ul>
<p>-version 3.26 on October 3, 2019
diff --git a/javassist.jar b/javassist.jar
index e23d4140..36ce5d9a 100644
--- a/javassist.jar
+++ b/javassist.jar
Binary files differ
diff --git a/src/main/javassist/compiler/MemberCodeGen.java b/src/main/javassist/compiler/MemberCodeGen.java
index f1ec84a5..48acd137 100644
--- a/src/main/javassist/compiler/MemberCodeGen.java
+++ b/src/main/javassist/compiler/MemberCodeGen.java
@@ -365,7 +365,7 @@ public class MemberCodeGen extends CodeGen {
sizeExpr.accept(this);
else
if (sizeExpr == null) {
- int s = init.length();
+ int s = init.size();
bytecode.addIconst(s);
}
else
@@ -414,7 +414,7 @@ public class MemberCodeGen extends CodeGen {
}
if (init != null) {
- int s = init.length();
+ int s = init.size();
ASTList list = init;
for (int i = 0; i < s; i++) {
bytecode.addOpcode(DUP);
diff --git a/src/main/javassist/compiler/Parser.java b/src/main/javassist/compiler/Parser.java
index 5290450c..ae73fb29 100644
--- a/src/main/javassist/compiler/Parser.java
+++ b/src/main/javassist/compiler/Parser.java
@@ -683,7 +683,7 @@ public final class Parser implements TokenId {
lex.get(); // '{'
if(lex.lookAhead() == '}'){
lex.get();
- return new ArrayInit(new IntConst(0,TokenId.IntConstant));
+ return new ArrayInit(null);
}
ASTree expr = parseExpression(tbl);
ArrayInit init = new ArrayInit(expr);
diff --git a/src/main/javassist/compiler/ast/ArrayInit.java b/src/main/javassist/compiler/ast/ArrayInit.java
index f992f426..0b87200e 100644
--- a/src/main/javassist/compiler/ast/ArrayInit.java
+++ b/src/main/javassist/compiler/ast/ArrayInit.java
@@ -25,10 +25,27 @@ public class ArrayInit extends ASTList {
/** default serialVersionUID */
private static final long serialVersionUID = 1L;
+ /**
+ * Constructs an object.
+ * @param firstElement maybe null when the initializer is <code>{}</code> (empty).
+ */
public ArrayInit(ASTree firstElement) {
super(firstElement);
}
+ /**
+ * Gets the number of the elements. Don't call {@link #length()}.
+ *
+ * @return the number of the elements.
+ */
+ public int size() {
+ int s = length();
+ if (s == 1 && head() == null)
+ return 0;
+ else
+ return s;
+ }
+
@Override
public void accept(Visitor v) throws CompileError { v.atArrayInit(this); }
diff --git a/src/test/javassist/JvstTest5.java b/src/test/javassist/JvstTest5.java
index 554538ae..ade41e8c 100644
--- a/src/test/javassist/JvstTest5.java
+++ b/src/test/javassist/JvstTest5.java
@@ -558,4 +558,20 @@ public class JvstTest5 extends JvstTestRoot {
Object obj = make(cc.getName());
assertEquals(71 + 22, invoke(obj, "run"));
}
+
+ // PR #294
+ public void testEmptyArrayInit() throws Exception {
+ CtClass cc = sloader.makeClass("test5.EmptyArrayInit");
+ CtMethod m = CtNewMethod.make("public int[] foo(){ int[] a = {}; return a; }", cc);
+ cc.addMethod(m);
+ CtMethod m2 = CtNewMethod.make("public int[] bar(){ int[] a = new int[]{}; return a; }", cc);
+ cc.addMethod(m2);
+ CtMethod m3 = CtNewMethod.make("public String[] baz(){ String[] a = { null }; return a; }", cc);
+ cc.addMethod(m3);
+ CtMethod m0 = CtNewMethod.make("public int run() { return foo().length + bar().length + baz().length; }", cc);
+ cc.addMethod(m0);
+ cc.writeFile();
+ Object obj = make(cc.getName());
+ assertEquals(1, invoke(obj, "run"));
+ }
}