JDK-8366018 : Beans.instantiate needs to describe the lookup procedure
  • Type: CSR
  • Component: client-libs
  • Sub-Component: java.beans
  • Priority: P3
  • Status: Finalized
  • Resolution: Unresolved
  • Fix Versions: 26
  • Submitted: 2025-08-22
  • Updated: 2025-09-28
Related Reports
CSR :  
Relates :  
Description
Summary
-------

Update the spec. of java.beans.Beans.instantiate() methods to describe the lookup process.

Problem
-------

The overload of Beans.instantiate() that described the lookup process was removed in JDK 26. It is now not described anywhere.

Solution
--------

Restore the text - in a slightly updated form - to the remaining overloads.

Specification
-------------

java.beans.Beans :
public static Object instantiate(ClassLoader cls, String beanName) throws IOException, ClassNotFoundException
```
+     * The bean is created based on a name relative to a class-loader.
+     * This name should be a {@linkplain ClassLoader##binary-name binary name} of a class such as "a.b.C".
+     * <p>
+     * The given name can indicate either a serialized object or a class.
+     * We first try to treat the  {@code beanName} as a serialized object
+     * name then as a class name.
+     * <p>
+     * When using the {@code beanName} as a serialized object name we convert the
+     * given  {@code beanName} to a resource pathname and add a trailing ".ser" suffix.
+     * We then try to load a serialized object from that resource.
+     * <p>
+     * For example, given a  {@code beanName} of "x.y", {@code Beans.instantiate} would first
+     * try to read a serialized object from the resource "x/y.ser" and if
+     * that failed it would try to load the class "x.y" and create an
+     * instance of that class.
+     *
```

public static Object instantiate(ClassLoader cls, String beanName,                                     BeanContext beanContext)    throws IOException, ClassNotFoundException
```
+     * The bean is created based on a name relative to a class-loader.
+     * This name should be a {@linkplain ClassLoader##binary-name binary name} of a class such as "a.b.C".
+     * <p>
+     * The given name can indicate either a serialized object or a class.
+     * We first try to treat the beanName as a serialized object
+     * name then as a class name.
+     * <p>
+     * When using the  {@code beanName} as a serialized object name we convert the
+     * given  {@code beanName} to a resource pathname and add a trailing ".ser" suffix.
+     * We then try to load a serialized object from that resource.
+     * <p>
+     * For example, given a  {@code beanName} of "x.y", {@code Beans.instantiate} would first
+     * try to read a serialized object from the resource "x/y.ser" and if
+     * that failed it would try to load the class "x.y" and create an
+     * instance of that class.
+     *

```

Comments
Moving to Provisional, not Approved. While the original wording "This name should be a dot-separated name such as "a.b.c"., etc. may have been adequate in JDK 1.1, I think we should be more precise in terminology for JDK 26. If what is mean is "The name should be a binary name of a top-level class such as "a..b.C" ..." where "binary name" is a link to https://download.java.net/java/early_access/jdk26/docs/api/java.base/java/lang/ClassLoader.html#binary-name, then that is the wording that should be used.
26-08-2025