Adding a static method in knownTypes is not working with Java17

Hello,

With Java 8/11, we successfully managed to call static methods inside our templates.

For example, it works fine with this class :

public class DateUtil {
  public static String format(String date) {
    return "...";
  }
}

and this configuration :

assembler = new DocumentAssembler();
assembler.getKnownTypes().add(DateUtil.class);
assembler.assembleDocument(..., ..., ...);

But, when we try the same thing with Java17, we’re facing this issue :

Caused by: java.lang.IllegalStateException: An error has been encountered at the end of expression 'DateUtil.format("..."))]'. Can not resolve method 'format' on type 'class [...].DateUtil'.

Is there anything else we have to do if we want to make it work with Java17 ?

Thanks,
Regards.

@Samoth
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): ASSEMBLYJAVA-34

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

1 Like

@Samoth

The problem arises from the newly introduced constraints on reflection usage in Java 17. This issue is acknowledged and essentially not a bug. To address it, insert the following code before assembling a document:

DocumentAssembler.setReflectionOptimization(false);

It’s important to note that this setting can be established just once, perhaps during application startup, as it impacts all subsequent documents being constructed.

@atir.tahir
Thank you for the quick feedback.

It works fine when I disable the reflection optimization (with setUseReflectionOptimization and not setReflectionOptimization).

The documentation isn’t explicit about the fact that it must be disabled with Java17, maybe this should be updated ?

Thanks again for your time.

1 Like

@Samoth

We’ll surely add this in documentation. Thanks.