changeset 54955:0996a11ae3e3 intrinsics-project

replace %% with % in the format string
author vromero
date Tue, 19 Feb 2019 21:20:07 -0500
parents 4c07ffe82f92
children 07dbd5da612f
files src/jdk.compiler/share/classes/com/sun/tools/javac/intrinsics/FormatterProcessor.java test/langtools/tools/javac/intrinsics/ConstantFormatStringTest.java test/langtools/tools/javac/intrinsics/EmptyFormatStringTest.java
diffstat 3 files changed, 40 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/intrinsics/FormatterProcessor.java	Tue Feb 19 19:45:00 2019 -0500
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/intrinsics/FormatterProcessor.java	Tue Feb 19 21:20:07 2019 -0500
@@ -138,7 +138,7 @@
         int numberOfConversionChars = strFormat.length() - strFormat.replaceAll("%", "").length();
         if (numberOfConversionChars == 0) {
             // just LDC the format str
-            return new Result.Ldc(constantFormat);
+            return new Result.Ldc(((String)constantFormat).replaceAll("%%", "%"));
         }
 
         String bsmName = getBSMName(ownerDesc, methodName, isStatic, hasLocale);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/intrinsics/ConstantFormatStringTest.java	Tue Feb 19 21:20:07 2019 -0500
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @summary check that no error occurs at execution time if the format string is empty
+ * @modules jdk.compiler/com.sun.tools.javac.util
+ * @run main ConstantFormatStringTest
+ */
+
+import com.sun.tools.javac.util.Assert;
+
+public class ConstantFormatStringTest {
+    public static void main(String... args) {
+        // no error
+        System.out.println(String.format("", "Bob", 1));
+        Assert.check(String.format("%%").equals("%"));
+    }
+}
--- a/test/langtools/tools/javac/intrinsics/EmptyFormatStringTest.java	Tue Feb 19 19:45:00 2019 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,34 +0,0 @@
-/*
- * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * @test
- * @summary check that no error occurs at execution time if the format string is empty
- * @run main EmptyFormatStringTest
- */
-
-public class EmptyFormatStringTest {
-    public static void main(String... args) {
-        System.out.println(String.format("", "Bob", 1));
-    }
-}