< prev index next >

test/jdk/java/lang/String/concat/WithSecurityManager.java

Print this page
rev 54607 : 8222895: StackOverflowError in custom security manager that relies on ClassSpecializer
Reviewed-by: TBD

@@ -24,11 +24,11 @@
 import java.security.Permission;
 
 /**
  * @test
  * @summary String concatenation fails with a custom SecurityManager that uses concatenation
- * @bug 8155090 8158851
+ * @bug 8155090 8158851 8222895
  * @requires !vm.graal.enabled
  *
  * @compile WithSecurityManager.java
  *
  * @run main/othervm -Xverify:all WithSecurityManager

@@ -53,28 +53,40 @@
         {
             SecurityManager sm = new SecurityManager() {
                 @Override
                 public void checkPermission(Permission perm) {
                     String abc = "abc";
-                    String full = abc + "def";
+                    int ival = perm.hashCode();
+                    String full = abc + "abc";
+                    // Contorted to avoid sweeping cases where we've
+                    // pre-generated commonly used species under the rug
+                    full = "abc" + ival + "def" + abc + "def" + abc + "def" +
+                           abc + "def" + ival + "def" + abc + "def" +
+                           abc + "def" + abc + "def" + abc + "def";
                 }
             };
             System.setSecurityManager(sm);
-            ClassLoader cl = new ClassLoader() {
-            };
+            ClassLoader cl = new ClassLoader() {};
         }
 
         // Second time should succeed to run after bootstrapping
         {
             SecurityManager sm = new SecurityManager() {
                 @Override
                 public void checkPermission(Permission perm) {
                     String abc = "abc";
-                    String full = abc + "def";
+                    int ival = perm.hashCode();
+                    String full = abc + "abc";
+                    // Contorted variant to avoid sweeping cases where we've
+                    // pre-generated commonly used species under the rug
+                    full = "abc" + ival + "def" + abc + "def" + abc + "def" +
+                            abc + "def" + ival + "def" + abc + "def" +
+                            abc + "def" + abc + "def" + abc + "def";
                 }
             };
+
+            // Provoke checkPermission invocation
             System.setSecurityManager(sm);
-            ClassLoader cl = new ClassLoader() {
-            };
+            ClassLoader cl = new ClassLoader() {};
         }
     }
 }
< prev index next >