rewrite
rewrite copied to clipboard
BlockStatementTemplateGenerator skips J.Parentheses.
I think I found another example where the method invocation replacement fails with exactly the same error message:
import oldPackage.A;
class MyClass
{
public void foo()
{
double value = 0;
if ((value = a.getValue()) != 0) {}
}
}
I debugged it a bit and saw that the resulting stub looks like that:
class __P__ { static native <T> T p(); static native <T> T[] arrp(); static native boolean booleanp(); static native byte bytep(); static native char charp(); static native double doublep(); static native int intp(); static native long longp(); static native short shortp(); static native float floatp();}class __M__ { static native Object any(Object o); static native <T> Object anyT();}class A{
public void foo(){
double value =0;
boolean __b9__ =value =
/*__TEMPLATE__*/__P__.<java.lang.Double>/*__p0__*/p().doubleValue()
;;}}
As you can see, for some reason it thinks that (value = a.getValue()) is a boolean.
Originally posted by @ZzetT in https://github.com/openrewrite/rewrite/issues/2063#issuecomment-1201125431
The BlockStatementTemplateGenerated does not check for J.Parentheses here.