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

String folding stops when a non-constant object is reached

    Details

    • Type: Enhancement
    • Status: New
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 9
    • Fix Version/s: tbd_major
    • Component/s: tools
    • Labels:

      Description

      Even after JDK-8134007, it seems javac only folds String-like constants from left to right, and it breaks as soon as non-constant is reached. See e.g.:

      public class StaticStringConst {

              static final int INT = 42;
              static final Object OBJ = new Object();
              static final String STR = "Foo";

              public static String m1() {
                      return "" + INT + STR + OBJ;
              }

              public static String m2() {
                      return "" + STR + INT + OBJ;
              }

              public static String m3() {
                      return "" + OBJ + INT + STR;
              }

              public static String m4() {
                      return "" + OBJ + STR + INT;
              }
      }

      m1() folds nicely to "42Foo" + OBJ, but m2() folds only to OBJ + 42 + "Foo".

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                mcimadamore Maurizio Cimadamore
                Reporter:
                shade Aleksey Shipilev
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: