JDK-8339881 : Indy string concat changes order of operations
  • Type: CSR
  • Component: tools
  • Sub-Component: javac
  • Priority: P4
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 11-pool,17-pool
  • Submitted: 2024-09-10
  • Updated: 2024-09-20
  • Resolved: 2024-09-20
Related Reports
CSR :  
Relates :  
Description
Summary
-------

This change causes the operands of string concatenation expressions
to be evaluated and converted to strings in the correct order when using
the invokedynamic-based strategies introduced in [JEP 280](https://openjdk.java.net/jeps/280).

Problem
-------

JLS 15.18.1 requires string conversion to be performed on the operands
of a string concatenation expression, and JLS 15.7.1 requires the operands
to be fully evaluated in left-to-right order. The current behavior of the
invokedynamic string concatenation strategies is to evaluate all operands,
and then separately convert them all to strings. The correct behavior is
to evaluate each argument and eagerly convert it to a string, in left-to-right
order.

Solution
--------

The solution is for the invokedynamic-based strategies to convert the
operands to strings as they are evaluated, and before they are passed
to the invokedynamic call site, to preserve the required evaluation order.

For some well-known types whose string representation is known to be
idempotent (including primitive types, their boxes, and java.lang.String)
the eager string conversion may be skipped.

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

No specification changes are required.

The proposed change to restore the behavior of the implementation
to match the specification can be found in https://git.openjdk.java.net/jdk/pull/5844.

Comments
Thanks to [~cushon] and [~shade] for re-raising this issue.
20-09-2024

Moving to Approved for 11u and 17u.
20-09-2024

Serving as technical reviewer of the backport CSR.
20-09-2024

[~shade] would you be willing to be a Reviewer for this CSR?
18-09-2024

Moving to Provisional. [~cushon], please get one or more technical reviewers before Finalizing the CSR for the second phase of review.
18-09-2024