Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8192036

Need to define the behaviour for 0 and 1 argument method type in StringConcatFactory.makeConcat

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P2 P2
    • 10
    • core-libs
    • None
    • behavioral
    • minimal
    • Existing implicit behaviour is now explicitly specified
    • Java API
    • SE

      Summary

      StringConcatFactory.makeConcat and StringConcatFactory.makeConcatWithConstants are underspecified with respect to 0 or 1 inputs when invoking the MethodHandle target of a returned CallSite.

      Solution

      Specify the concatenation behaviour cases for 0 or 1 inputs (note an input may be an argument or a constant). For 0 inputs an empty string is returned, for 1 input the value converted to a String and then returned.

      Specification

      diff -r 5bb3d34ffeb1 src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java
      --- a/src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java Mon Nov 27 15:47:27 2017 -0800
      +++ b/src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java Tue Nov 28 12:55:47 2017 -0800
      @@ -385,9 +385,16 @@
            * invoked, it returns the result of String concatenation, taking all
            * function arguments passed to the linkage method as inputs for
            * concatenation. The target signature is given by {@code concatType}.
      -     * The arguments are concatenated as per requirements stated in JLS 15.18.1
      -     * "String Concatenation Operator +". Notably, the inputs are converted as
      -     * per JLS 5.1.11 "String Conversion", and combined from left to right.
      +     * For a target accepting:
      +     * <ul>
      +     *     <li>zero inputs, concatenation results in an empty string;</li>
      +     *     <li>one input, concatenation results in the single
      +     *     input converted as per JLS 5.1.11 "String Conversion"; otherwise</li>
      +     *     <li>two or more inputs, the inputs are concatenated as per
      +     *     requirements stated in JLS 15.18.1 "String Concatenation Operator +".
      +     *     The inputs are converted as per JLS 5.1.11 "String Conversion",
      +     *     and combined from left to right.</li>
      +     * </ul>
            *
            * <p>Assume the linkage arguments are as follows:
            *
      @@ -452,10 +464,17 @@
            * invoked, it returns the result of String concatenation, taking all
            * function arguments and constants passed to the linkage method as inputs for
            * concatenation. The target signature is given by {@code concatType}, and
      -     * does not include constants. The arguments are concatenated as per requirements
      -     * stated in JLS 15.18.1 "String Concatenation Operator +". Notably, the inputs
      -     * are converted as per JLS 5.1.11 "String Conversion", and combined from left
      -     * to right.
      +     * does not include constants.
      +     * For a target accepting:
      +     * <ul>
      +     *     <li>zero inputs, concatenation results in an empty string;</li>
      +     *     <li>one input, concatenation results in the single
      +     *     input converted as per JLS 5.1.11 "String Conversion"; otherwise</li>
      +     *     <li>two or more inputs, the inputs are concatenated as per
      +     *     requirements stated in JLS 15.18.1 "String Concatenation Operator +".
      +     *     The inputs are converted as per JLS 5.1.11 "String Conversion",
      +     *     and combined from left to right.</li>
      +     * </ul>
            *
            * <p>The concatenation <em>recipe</em> is a String description for the way to
            * construct a concatenated String from the arguments and constants. The

            psandoz Paul Sandoz
            pgundarlahal Prashanthram Gundarlahally
            Mandy Chung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: