-1

Javassist gives me this error:

Caused by: javassist.compiler.SyntaxError: syntax error near "oolean do() {
  Obje"
        at javassist.compiler.Parser.parseMember1(Parser.java:55) ~[?:?]
        at javassist.compiler.Javac.compile(Javac.java:90) ~[?:?]
        at javassist.CtNewMethod.make(CtNewMethod.java:74) ~[?:?]
        at javassist.CtNewMethod.make(CtNewMethod.java:45) ~[?:?]
        at javassist.CtMethod.make(CtMethod.java:132) ~[?:?]

when it tries to compile this part of a generated class:

public boolean do() {
  ObjectContainer[] $cArgs = ObjectContainer.fromObjects(ArrayMaker.fromParameters());
  SuperSwitch $switch = SuperSwitch.newInstance();
  boolean $returned = (boolean) this.methodCalled_boolean("boolean do()", $switch, $cArgs);
  Object[] $mArgs = ObjectContainer.toObjects($cArgs);
  if($switch.callSuper()) {
    if($switch.isReplace()) {
      return (boolean) $returned;    } else {
      return (boolean) super.do();
    }
  } else {
    return (boolean) false;
  }
}

From what I can see, there isn't anything wrong with the method syntax, and other similar boolean methods in the same class compile just fine.

1 Answers1

2

do is a keyword and is not a valid method identifier, so there is a syntax error.

See https://docs.oracle.com/javase/tutorial/java/nutsandbolts/while.html

Roman Puchkovskiy
  • 11,415
  • 5
  • 36
  • 72
  • Yeah, I'm aware that `do` is a keyword. But my code actually takes existing methods from another class and interjects them, meaning there has to be *some* way to have a method named `do`, right? Edit: https://yeleha.co/2BRu2gd - I'm guessing an obfuscator renamed it... – inventivetalent Feb 04 '18 at 09:21
  • From the point of view of the JVM, `do` is a valid method name. The only problem is that you cannot generate a class containing a method with such a name *using a complient Java compiler*. But if some other tool generates it, you may get a class file containing a method called `do`. Once again: if such a method gets generated, you cannot even call it from normal Java code, maybe only via reflection. Are you sure your classfile actually has that method called `do`? What does `javap` output for that classfile? – Roman Puchkovskiy Feb 04 '18 at 09:32
  • javap also shows the `do` method in the original class: https://yeleha.co/2BRAV13 – inventivetalent Feb 04 '18 at 10:31