NoSuchMethodException in ExpressionMethodVisitor.visitMethodInsn if using method reference
Closed this issue · 3 comments
Hello,
I have been trying the basic example, but for some reason it doesn't work.
This is what I have:
public class Test {
public static void main(String[] args) {
System.setProperty("jdk.internal.lambda.dumpProxyClasses", System.getProperty("java.io.tmpdir"));
Fluent<Customer> f = new Fluent<>();
System.out.println(f.property(customer -> customer.getName()).getParsed());
//System.out.println(f.property(Customer::getName).getParsed());
}
}
This works fine and prints: {(Customer P0) -> P0.getName()}
But if I try to replace the lambda with a method reference (as in the commented-out line), I get this exception:
Exception in thread "main" java.lang.RuntimeException: java.lang.NoSuchMethodException: java.lang.Object.getName()
at com.trigersoft.jaque.expression.ExpressionMethodVisitor.visitMethodInsn(ExpressionMethodVisitor.java:756)
at org.objectweb.asm.ClassReader.a(Unknown Source)
at org.objectweb.asm.ClassReader.b(Unknown Source)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at com.trigersoft.jaque.expression.ExpressionClassVisitor.parse(ExpressionClassVisitor.java:195)
at com.trigersoft.jaque.expression.ExpressionClassVisitor.lambda(ExpressionClassVisitor.java:109)
at com.trigersoft.jaque.expression.LambdaExpression.parse(LambdaExpression.java:91)
at Fluent.property(Fluent.java:17)
at Test.main(Test.java:8)
Caused by: java.lang.NoSuchMethodException: java.lang.Object.getName()
at java.lang.Class.getDeclaredMethod(Class.java:2130)
at com.trigersoft.jaque.expression.Expression.getDeclaredMethod(Expression.java:1277)
at com.trigersoft.jaque.expression.Expression.invoke(Expression.java:1225)
at com.trigersoft.jaque.expression.ExpressionMethodVisitor.visitMethodInsn(ExpressionMethodVisitor.java:753)
... 9 more
Thanks for your work, have a good day.
This case, as you describe it, is covered in unit test, which successfully passes. Can you create another test that fails and send a pull request or send a zip with a full example?
Hi,
Please find the ZIP attached.
Please unzip and run from the directory "jaque" via Maven:
mvn package exec:java
It's a fairly simple example, so I assume it is something to do with my environment (or I'm totally missing something):
- Windows 10
- java version "1.8.0_112"
- Java(TM) SE Runtime Environment (build 1.8.0_112-b15)
- Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)
Thanks!
Apologies, just realized that I was using an old version 2.0.2, because my IntelliJ for some reason could not download 2.1.2 (Maven from command line could). It has apparently been fixed in the latest version.