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

String concatenation fails with a custom SecurityManager that uses concatenation

    XMLWordPrintable

    Details

      Description

      Lets say we have a custom security manager that uses string concatenation (+) inside the method checkPermission(Permission).
      When we call the method that does permission checking, it throws a java.lang.BootstrapMethodError.

      Minimized test:
      -----------------------------------------

          SecurityManager sm = new SecurityManager() {

                  @Override
                  public void checkPermission(Permission perm) {
                      String abc = "abc";
                      String full = abc + "def";
                  }
              };
              System.setSecurityManager(sm);
              ClassLoader cl = new ClassLoader() {};
          }
      -----------------------------------------

      Interesting that the spec for j.l.String says the following regarding concatenation:
      "The Java language provides special support for the string concatenation operator ( + ), ... String concatenation is implemented through the StringBuilder(or StringBuffer) class and its append method."
      However, if we will replace {abc + "def"} with {new StringBuffer().append(abc).append("def").toString()}, the exception won't be thrown.

      Reproduced with jdk9b104 and later.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              shade Aleksey Shipilev
              Reporter:
              evotchen Elena Votchennikova (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: