Sorry, Ben, tried it, but this is not working.

    private final String x = "...";
    public final String x = "...";

throws: "Update to non-static final field ...x... attempted from a different method (initializeInstance) than the initializer method <init>"
which is correct, because the field isn't static.


Using

    private static final String x = "...";

works, but requires additional get method.


In contrast

    public static final String x = "...";

is not accessible from the page (tml). Exception is:

"Exception assembling root component of page X: Could not convert 'x' into a component parameter binding: Exception generating conduit for expression 'x': Class X does not contain a property (or public field) named 'x'.


Tested with T5.8.3 and OpenJDK 11.07


Jens



Am 01.08.23 um 15:29 schrieb Ben Weidig:
Hi Jens,

I was looking into static fields and the @Property annotation worker the
other day but stopped, as I realized you can use "public static final"
fields directly in the TML without any additional work.

So the following code should be fine:

public final String[] keys = new String[] {
          "A", "B", "C"
      };

Use it as usual, like "prop:keys" in the TML


Private fields that are only exposed to the TML would be preferable, but
it's a simple workaround, and I'm not sure how easy it would be to
implement it in the PlasticClass transformation.

The change in final handling is most likely related to an older ticket of
mine

https://issues.apache.org/jira/browse/TAP5-2630

Cheers
Ben


On Tue, Aug 1, 2023 at 2:57 PM Jens Breitenstein <jb//
j-b-s...@toc-mailserver.de> wrote:

HI!

I noticed due to JDK 11 there is a subtile change in handling of final
fields and initialization.

On rare cases we used final fields including @Property(write = false),
which is no longer working. Example:

      @Property(write="false") private final String[] _keys = new String[] {
          "A", "B", "C"
      };

This allowed us to initialize the field once, but still access it from
the page (tml). Using JDK 11 and T5.8.x this now throws an exception.
But modifying it to

      private static final String[] _keys = new String[] {
          "A", "B", "C"
      };

      public String[] getKeys() {
          return _keys;
      };

requires an additional instance method, because @Property can't handle
static fields. Are there any plans to solve it by Tapestry itself (eg to
add this "get" method automatically while class transformation is
applyed in case a field is marked as static and and property)?

Currently I do not see another workaround apart rewriting parts like
this, right?

Thanks

Jens



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to