Having looked into this, the best answer I can come up with is that this is a bug of omission. According to the documentation it "should work", but it doesn't. Luckily the workaround is trivial, simply initialize your arrays with "new Object[0];".
Javassist CtMethod.make() gives "syntax error" on array initialization using empty brackets
-
01-04-2022 - |
Question
I am using Javassist to build a runtime class. I am creating a CtMethod:
CtMethod m = CtMethod.make(constructMethodSource, bclass);
Inside "constructMethodSource" is this line which is a legitimate line of Java code:
java.lang.Object[] args = new java.lang.Object[] {};
With that, make() throws a syntax error:
[source error] syntax error near "bject[] {};"
I played with it and instead initialized my empty array a different way:
java.lang.Object[] args = new java.lang.Object[0];
That made Javassist happy but I'm wondering why does Javassist choke on the first line? Is that a known limitation or a bug or am I doing something foolish?
Solution
OTHER TIPS
http://www.csg.is.titech.ac.jp/~chiba/javassist/tutorial/tutorial2.html (section 4.7) says: Array initializers, a comma-separated list of expressions enclosed by braces { and }, are not available unless the array dimension is one.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow