< prev index next >

test/java/lang/String/concat/StringConcatFactoryInvariants.java

Print this page
rev 17632 : 8186500: StringConcatFactory.makeConcatWithConstants throws AssertionError when recipe contains non-String constants
Reviewed-by: shade, psandoz

@@ -68,11 +68,17 @@
     public static void main(String[] args) throws Throwable {
         MethodHandles.Lookup lookup = MethodHandles.lookup();
         String methodName = "foo";
         MethodType mt = MethodType.methodType(String.class, String.class, int.class);
         String recipe = "" + TAG_ARG + TAG_ARG + TAG_CONST;
-        String[] constants = new String[]{"bar"};
+        Object[] constants = new String[] { "bar" };
+        Object[] intConstants = new Integer[] { 1 };
+        Object[] shortConstants = new Short[] { 1 };
+        Object[] longConstants = new Long[] { 1L };
+        Object[] booleanConstants = new Boolean[] { true };
+        Object[] charConstants = new Character[] { 'a' };
+        Object[] byteConstants = new Byte[] { 1 };
 
         final int LIMIT = 200;
 
         // Simple factory: check for dynamic arguments overflow
         Class<?>[] underThreshold = new Class<?>[LIMIT - 1];

@@ -111,10 +117,20 @@
         {
             CallSite cs = StringConcatFactory.makeConcatWithConstants(lookup, methodName, mt, recipe, constants);
             test("foo42bar", (String) cs.getTarget().invokeExact("foo", 42));
         }
 
+        {
+            CallSite cs = StringConcatFactory.makeConcatWithConstants(lookup, methodName, mt, recipe, intConstants);
+            test("foo421", (String) cs.getTarget().invokeExact("foo", 42));
+        }
+
+        {
+            CallSite cs = StringConcatFactory.makeConcatWithConstants(lookup, methodName, mt, recipe, booleanConstants);
+            test("foo42true", (String) cs.getTarget().invokeExact("foo", 42));
+        }
+
         // Simple factory, check for nulls:
         failNPE("Lookup is null",
                 () -> StringConcatFactory.makeConcat(null, methodName, mt));
 
         failNPE("Method name is null",

@@ -125,21 +141,93 @@
 
         // Advanced factory, check for nulls:
         failNPE("Lookup is null",
                 () -> StringConcatFactory.makeConcatWithConstants(null, methodName, mt, recipe, constants));
 
+        failNPE("Lookup is null",
+                () -> StringConcatFactory.makeConcatWithConstants(null, methodName, mt, recipe, shortConstants));
+
+        failNPE("Lookup is null",
+                () -> StringConcatFactory.makeConcatWithConstants(null, methodName, mt, recipe, intConstants));
+
+        failNPE("Lookup is null",
+                () -> StringConcatFactory.makeConcatWithConstants(null, methodName, mt, recipe, longConstants));
+
+        failNPE("Lookup is null",
+                () -> StringConcatFactory.makeConcatWithConstants(null, methodName, mt, recipe, booleanConstants));
+
+        failNPE("Lookup is null",
+                () -> StringConcatFactory.makeConcatWithConstants(null, methodName, mt, recipe, byteConstants));
+
+        failNPE("Lookup is null",
+                () -> StringConcatFactory.makeConcatWithConstants(null, methodName, mt, recipe, charConstants));
+
         failNPE("Method name is null",
                 () -> StringConcatFactory.makeConcatWithConstants(lookup, null, mt, recipe, constants));
 
+        failNPE("Method name is null",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, null, mt, recipe, shortConstants));
+
+        failNPE("Method name is null",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, null, mt, recipe, intConstants));
+
+        failNPE("Method name is null",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, null, mt, recipe, longConstants));
+
+        failNPE("Method name is null",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, null, mt, recipe, booleanConstants));
+
+        failNPE("Method name is null",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, null, mt, recipe, byteConstants));
+
+        failNPE("Method name is null",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, null, mt, recipe, charConstants));
+
         failNPE("MethodType is null",
                 () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, null, recipe, constants));
 
+        failNPE("MethodType is null",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, null, recipe, shortConstants));
+
+        failNPE("MethodType is null",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, null, recipe, intConstants));
+
+        failNPE("MethodType is null",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, null, recipe, longConstants));
+
+        failNPE("MethodType is null",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, null, recipe, booleanConstants));
+
+        failNPE("MethodType is null",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, null, recipe, byteConstants));
+
+        failNPE("MethodType is null",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, null, recipe, charConstants));
+
         failNPE("Recipe is null",
                 () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, mt, null, constants));
 
+        failNPE("Recipe is null",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, mt, null, shortConstants));
+
+        failNPE("Recipe is null",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, mt, null, intConstants));
+
+        failNPE("Recipe is null",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, mt, null, longConstants));
+
+        failNPE("Recipe is null",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, mt, null, booleanConstants));
+
+        failNPE("Recipe is null",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, mt, null, byteConstants));
+
+        failNPE("Recipe is null",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, mt, null, charConstants));
+
         failNPE("Constants vararg is null",
-                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, mt, recipe, null));
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, mt, recipe, (Object[])null));
 
         // Simple factory, check for return type
         fail("Return type: void",
                 () -> StringConcatFactory.makeConcat(lookup, methodName, MethodType.methodType(void.class, String.class, int.class)));
 

@@ -160,25 +248,97 @@
 
         // Advanced factory, check for return types
         fail("Return type: void",
                 () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, MethodType.methodType(void.class, String.class, int.class), recipe, constants));
 
+        fail("Return type: void",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, MethodType.methodType(void.class, String.class, int.class), recipe, intConstants));
+
+        fail("Return type: void",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, MethodType.methodType(void.class, String.class, int.class), recipe, shortConstants));
+
+        fail("Return type: void",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, MethodType.methodType(void.class, String.class, int.class), recipe, longConstants));
+
+        fail("Return type: void",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, MethodType.methodType(void.class, String.class, int.class), recipe, booleanConstants));
+
+        fail("Return type: void",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, MethodType.methodType(void.class, String.class, int.class), recipe, byteConstants));
+
+        fail("Return type: void",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, MethodType.methodType(void.class, String.class, int.class), recipe, charConstants));
+
         fail("Return type: int",
                 () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, MethodType.methodType(int.class, String.class, int.class), recipe, constants));
 
         fail("Return type: StringBuilder",
                 () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, MethodType.methodType(StringBuilder.class, String.class, int.class), recipe, constants));
 
         ok("Return type: Object",
                 () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, MethodType.methodType(Object.class, String.class, int.class), recipe, constants));
 
+        ok("Return type: Object",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, MethodType.methodType(Object.class, String.class, int.class), recipe, intConstants));
+
+        ok("Return type: Object",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, MethodType.methodType(Object.class, String.class, int.class), recipe, shortConstants));
+
+        ok("Return type: Object",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, MethodType.methodType(Object.class, String.class, int.class), recipe, longConstants));
+
+        ok("Return type: Object",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, MethodType.methodType(Object.class, String.class, int.class), recipe, booleanConstants));
+
+        ok("Return type: Object",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, MethodType.methodType(Object.class, String.class, int.class), recipe, byteConstants));
+
+        ok("Return type: Object",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, MethodType.methodType(Object.class, String.class, int.class), recipe, charConstants));
+
         ok("Return type: CharSequence",
                 () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, MethodType.methodType(CharSequence.class, String.class, int.class), recipe, constants));
 
+        ok("Return type: CharSequence",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, MethodType.methodType(CharSequence.class, String.class, int.class), recipe, intConstants));
+
+        ok("Return type: CharSequence",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, MethodType.methodType(CharSequence.class, String.class, int.class), recipe, shortConstants));
+
+        ok("Return type: CharSequence",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, MethodType.methodType(CharSequence.class, String.class, int.class), recipe, longConstants));
+
+        ok("Return type: CharSequence",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, MethodType.methodType(CharSequence.class, String.class, int.class), recipe, booleanConstants));
+
+        ok("Return type: CharSequence",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, MethodType.methodType(CharSequence.class, String.class, int.class), recipe, byteConstants));
+
+        ok("Return type: CharSequence",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, MethodType.methodType(CharSequence.class, String.class, int.class), recipe, charConstants));
+
         ok("Return type: Serializable",
                 () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, MethodType.methodType(Serializable.class, String.class, int.class), recipe, constants));
 
+        ok("Return type: Serializable",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, MethodType.methodType(Serializable.class, String.class, int.class), recipe, intConstants));
+
+        ok("Return type: Serializable",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, MethodType.methodType(Serializable.class, String.class, int.class), recipe, shortConstants));
+
+        ok("Return type: Serializable",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, MethodType.methodType(Serializable.class, String.class, int.class), recipe, longConstants));
+
+        ok("Return type: Serializable",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, MethodType.methodType(Serializable.class, String.class, int.class), recipe, booleanConstants));
+
+        ok("Return type: Serializable",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, MethodType.methodType(Serializable.class, String.class, int.class), recipe, byteConstants));
+
+        ok("Return type: Serializable",
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, MethodType.methodType(Serializable.class, String.class, int.class), recipe, charConstants));
+
         // Simple factory: check for dynamic arguments overflow
         ok("Dynamic arguments is under limit",
                 () -> StringConcatFactory.makeConcat(lookup, methodName, mtUnderThreshold));
 
         ok("Dynamic arguments is at the limit",

@@ -214,22 +374,22 @@
         fail("Dynamic arguments and recipe mismatch",
                 () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, mtThreshold, recipeOverThreshold, constants));
 
         // Test passing array as constant
         {
-            String[] arg = {"boo", "bar"};
+            Object[] arg = {"boo", "bar"};
 
             CallSite cs1 = StringConcatFactory.makeConcatWithConstants(lookup, methodName, MethodType.methodType(String.class, int.class), "" + TAG_ARG + TAG_CONST + TAG_CONST, arg);
             test("42boobar", (String) cs1.getTarget().invokeExact(42));
         }
 
         // Test passing null constant
         ok("Can pass regular constants",
                 () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, MethodType.methodType(String.class, int.class), "" + TAG_ARG + TAG_CONST, "foo"));
 
         failNPE("Cannot pass null constants",
-                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, MethodType.methodType(String.class, int.class), "" + TAG_ARG + TAG_CONST, new String[]{null}));
+                () -> StringConcatFactory.makeConcatWithConstants(lookup, methodName, MethodType.methodType(String.class, int.class), "" + TAG_ARG + TAG_CONST, new Object[]{null}));
 
         // Simple factory: test empty arguments
         ok("Ok to pass empty arguments",
                 () -> StringConcatFactory.makeConcat(lookup, methodName, mtEmpty));
 
< prev index next >