String concatenation order of operations

Liam Miller-Cushon cushon at
Wed Sep 8 00:40:45 UTC 2021

I noticed that the result of string concatenation is different for the
invokedynamic and inline strategies when the arguments have side effects.

With the inline strategy, each subexpression is evaluated and converted to
a string in order. With indy each subexpression is evaluated in order *but
not converted to a string*, and later each subexpression is converted to a
string in order.

Is one of these behaviours more correct than the other?

class T {
  static String test() {
    StringBuilder builder = new StringBuilder("foo");
    return "" + builder + builder.append("bar");

  public static void main(String[] args) {

$ javac -XDstringConcat=inline ; java T

$ javac -XDstringConcat=indy ; java T

I read some of the related discussion about the spec requirements for
string concatenation in [1], and also some of the discussion around
JEP-280, and didn't find a conclusive answer. There was a bug [2] about the
evaluation order of string concat subexpressions with indy, but that was
about converting the arguments to strings in the wrong order.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the compiler-dev mailing list