JDK-8221255 : LambdaMetafactory: validate inputs and improve documentation
  • Type: CSR
  • Component: core-libs
  • Sub-Component: java.lang.invoke
  • Priority: P4
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 17
  • Submitted: 2019-03-21
  • Updated: 2021-06-07
  • Resolved: 2021-06-07
Related Reports
CSR :  
Description
Summary
-------

Document and enforce the conditions under which invalid arguments will cause a `RuntimeException` to be thrown by the `LambdaMetafactory` methods.

Problem
-------

The `LambdaMetafactory` methods fail to validate their inputs. When invoked directly (as opposed to standard usage by `javac`), invalid arguments lead to unspecified, ad hoc `RuntimeException`s or other surprising behavior.

Solution
--------

Specify four exceptions that can be thrown: `LambdaConversionException`, `NullPointerException`, `IllegalArgumentException`, and `SecurityException`. Describe the conditions under which they will be thrown.

This is a behavioral change: certain nonstandard usages of `LambdaMetafactory` will result in new or different exceptions.

Also make some clarifying revisions to specification, such as more accurately naming parameters to reflect their behavior rather than the specific way `javac` uses them.

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

Diff of LambdaMetafactory.java is attached. See also the [code review](https://github.com/openjdk/jdk/pull/4346).

Comments
Moving to Approved for JDK 17.
07-06-2021

Seeking re-approval for 17. The changes are almost identical to the previously-approved iteration. Specifically: - JDK-8233527 revised the requirements for the Lookup object, stating that it must have full privilege access. This patch updates the associated description of LambdaConversionException - A couple of renamings suggested by reviewers: `interfaces` --> `altInterfaces` and `bridges` --> `altMethods`. - Minor javadoc changes, like adjusting the markup
04-06-2021

The parameter renames comprise a larger fraction of the diff, but the renames and more rigorous exceptional behavior seems reasonable. Moving to Approved.
21-03-2019

There is a change that moves an `@implNote` to an `@apiNote`. It was incorrect to tag the discussion as an implementation detail: the set of method handles that are supported is not an implementation choice.
21-03-2019