We're sorry Aspose doesn't work properply without JavaScript enabled.

# Calculation formulas broken in Java 17

We’re using formulas like this:
<<[getPricePurchase().doubleValue() * getQuantity().doubleValue()]:"# ##0.00">>
The expression getPricePurchase() produces a BigDecimal object, while getQuantity() is a Double.
It had been working well on Java 11. When upgrading to Java 17, we got this error:
An error has been encountered at the end of expression ‘getPricePurchase().doubleValue() * getQuantity().doubleValue()]:’. Can not apply operator '’ to operands of type ‘class java.lang.Object’ and ‘class java.lang.Object’.*
What can I do to fix it?

@thai I have tested the scenario on my side and the formula is calculated properly on my side. Could you please create a simple template and code that will allow us to reproduce the problem? We will check the issue and provide you more information.

Indeed, looks like that’s not the case. Something else is wrong - I’ll update the question when having more information.

@thai I have noticed that code like the following does not work and throws an exception:

Document doc = new Document("C:\\Temp\\in.docx");
MessageTestClass sender = new MessageTestClass("LINQ Reporting Engine", "Hello, World");
ReportingEngine engine = new ReportingEngine();
engine.buildReport(doc, sender, "s");
doc.save("C:\\Temp\\out.docx");


To fix the problem it is required to disable UseReflectionOptimization.

ReportingEngine.setUseReflectionOptimization(false);


Is this the problem you have encountered?

Thanks a lot for your support, @alexey.noskov.
Yes, that’s exactly the case. After I added that statement, everything goes well again.
Thank you.

@thai Thank you for confirmation. I have linked this thread to the appropriate issue WORDSJAVA-2682. We will let you know once it is resolved.

1 Like