string concatenation versus null

XMLWordPrintable

    • Type: Bug
    • Resolution: Not an Issue
    • Priority: P4
    • None
    • Affects Version/s: 5.0
    • Component/s: specification
    • None
    • generic
    • solaris_8

      String concatenation is not fully specified. Specifically, in this case

          String s1 = null;
          Object s2 = "foo";

          System.out.println(s1 + s2);

      The current spec applies the string conversion to s2, but not to s1. This suggests that this should throw a NullPointerException, because

          s1.append(s2)

      would throw such an error.

      It has been suggested that javac should use .append instead of a StringBuffer when the static type of the two operands are both String, but the behavior is obviously not equivalent to the current behavior (using StringBuffer).

      Can you please update JLS3 to more clearly specify the behavior.

            Assignee:
            Alex Buckley
            Reporter:
            Neal Gafter (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: