Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8262506

Support records in Dynalink

    XMLWordPrintable

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P4
    • Resolution: Approved
    • Fix Version/s: 17
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Compatibility Kind:
      behavioral
    • Compatibility Risk:
      minimal
    • Compatibility Risk Description:
      Hide
      In presence of both a record component accessor foo() and a separate method getFoo() on the record class, a scripting language using Dynalink would, before this change, link to getFoo() as the property getter for "foo". After this change, it will link to foo(). The occurrence of both styles of getters on a record class is highly unlikely.

      A scripting language that before this change would fail to find record components as properties on record instances would now successfully find them.
      Show
      In presence of both a record component accessor foo() and a separate method getFoo() on the record class, a scripting language using Dynalink would, before this change, link to getFoo() as the property getter for "foo". After this change, it will link to foo(). The occurrence of both styles of getters on a record class is highly unlikely. A scripting language that before this change would fail to find record components as properties on record instances would now successfully find them.
    • Interface Kind:
      Java API
    • Scope:
      JDK

      Description

      Summary

      The change proposes that Dynalink's built-in jdk.dynalink.beans.BeansLinker should expose record components as read-only properties.

      Problem

      BeansLinker currently recognizes JavaBeans-style getter methods on a class as property getters (so, isXxx() or getXxx()) but does not recognize record component accessors on record classes as property getters. It is a reasonable expectation that if a user uses Dynalink to link a property-reading call site against a record class and the property name matches a record component, the call site should be linked with a call to the accessor method.

      Solution

      Implement behavior where accessor methods in record classes are recognized as property getters for properties whose names match record components. Give those accessors priority over other getters (if a record class has a component accessor foo() and a method getFoo() then the component accessor gets linked for "GET:PROPERTY:foo" operation.

      Specification

      The normative change is the description of the new behavior in BeansLinker class' JavaDoc:

      diff --git a/src/jdk.dynalink/share/classes/jdk/dynalink/beans/BeansLinker.java b/src/jdk.dynalink/share/classes/jdk/dynalink/beans/BeansLinker.java
      index 470bd32..386f386 100644
      --- a/src/jdk.dynalink/share/classes/jdk/dynalink/beans/BeansLinker.java
      +++ b/src/jdk.dynalink/share/classes/jdk/dynalink/beans/BeansLinker.java
      @@ -78,10 +78,14 @@ import jdk.dynalink.linker.TypeBasedGuardingDynamicLinker;
        * calls to all objects that no other linker recognized. Specifically, this
        * linker will:
        * <ul>
      + * <li>if the object is a {@link java.lang.Record record}, expose all public accessors of
      + * record components as property getters for {@link StandardOperation#GET} operations
      + * in the {@link StandardNamespace#PROPERTY} namespace;</li>
        * <li>expose all public methods of form {@code setXxx()}, {@code getXxx()},
        * and {@code isXxx()} as property setters and getters for
        * {@link StandardOperation#SET} and {@link StandardOperation#GET} operations in the
      - * {@link StandardNamespace#PROPERTY} namespace;</li>
      + * {@link StandardNamespace#PROPERTY} namespace, except for getters for properties
      + * with names already handled by record component getters;</li>
        * <li>expose all public methods for retrieval for
        * {@link StandardOperation#GET} operation in the {@link StandardNamespace#METHOD} namespace;
        * the methods thus retrieved can then be invoked using {@link StandardOperation#CALL}.</li>

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              attila Attila Szegedi
              Reporter:
              attila Attila Szegedi
              Reviewed By:
              Sundararajan Athijegannathan
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: