-
CSR
-
Resolution: Approved
-
P4
-
None
-
behavioral
-
minimal
-
-
Java API
-
JDK
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>
- csr of
-
JDK-8262503 Support records in Dynalink
- Resolved