This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/main by this push:
     new 6c1c699  BZ 54377 - Update code generation to use valueOf for boxed 
primitives
6c1c699 is described below

commit 6c1c6994415e008a5cf57d331ce618c24095389d
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Jun 25 13:14:26 2021 +0100

    BZ 54377 - Update code generation to use valueOf for boxed primitives
    
    Constructors are deprecated as of Java 9 and marked for removal as of
    Java 16.
    https://bz.apache.org/bugzilla/show_bug.cgi?id=65377
---
 java/org/apache/jasper/compiler/JspUtil.java | 32 ++++++++++++++--------------
 webapps/docs/changelog.xml                   |  6 ++++++
 2 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/java/org/apache/jasper/compiler/JspUtil.java 
b/java/org/apache/jasper/compiler/JspUtil.java
index 447dc84..211ffe4 100644
--- a/java/org/apache/jasper/compiler/JspUtil.java
+++ b/java/org/apache/jasper/compiler/JspUtil.java
@@ -427,10 +427,10 @@ public class JspUtil {
                     + s + ", java.lang.Boolean.class)";
         } else {
             if (s == null || s.length() == 0) {
-                return "new java.lang.Boolean(false)";
+                return "java.lang.Boolean.FALSE";
             } else {
                 // Detect format error at translation time
-                return "new java.lang.Boolean(" + 
Boolean.valueOf(s).toString() + ")";
+                return "java.lang.Boolean.valueOf(" + Generator.quote(s) + ")";
             }
         }
     }
@@ -455,10 +455,10 @@ public class JspUtil {
                     + s + ", java.lang.Byte.class)";
         } else {
             if (s == null || s.length() == 0) {
-                return "new java.lang.Byte((byte) 0)";
+                return "java.lang.Byte.valueOf((byte) 0)";
             } else {
                 // Detect format error at translation time
-                return "new java.lang.Byte((byte)" + 
Byte.valueOf(s).toString() + ")";
+                return "java.lang.Byte.valueOf(" + Generator.quote(s) + ")";
             }
         }
     }
@@ -484,11 +484,11 @@ public class JspUtil {
                     + s + ", java.lang.Character.class)";
         } else {
             if (s == null || s.length() == 0) {
-                return "new java.lang.Character((char) 0)";
+                return "java.lang.Character.valueOf((char) 0)";
             } else {
                 char ch = s.charAt(0);
                 // this trick avoids escaping issues
-                return "new java.lang.Character((char) " + (int) ch + ")";
+                return "java.lang.Character.valueOf((char) " + (int) ch + ")";
             }
         }
     }
@@ -513,10 +513,10 @@ public class JspUtil {
                     + s + ", Double.class)";
         } else {
             if (s == null || s.length() == 0) {
-                return "new java.lang.Double(0)";
+                return "java.lang.Double.valueOf(0)";
             } else {
                 // Detect format error at translation time
-                return "new java.lang.Double(" + Double.valueOf(s).toString() 
+ ")";
+                return "java.lang.Double.valueOf(" + Generator.quote(s) + ")";
             }
         }
     }
@@ -541,10 +541,10 @@ public class JspUtil {
                     + s + ", java.lang.Float.class)";
         } else {
             if (s == null || s.length() == 0) {
-                return "new java.lang.Float(0)";
+                return "java.lang.Float.valueOf(0)";
             } else {
                 // Detect format error at translation time
-                return "new java.lang.Float(" + Float.valueOf(s).toString() + 
"f)";
+                return "java.lang.Float.valueOf(" + Generator.quote(s) + ")";
             }
         }
     }
@@ -568,10 +568,10 @@ public class JspUtil {
                     + s + ", java.lang.Integer.class)";
         } else {
             if (s == null || s.length() == 0) {
-                return "new java.lang.Integer(0)";
+                return "java.lang.Integer.valueOf(0)";
             } else {
                 // Detect format error at translation time
-                return "new java.lang.Integer(" + 
Integer.valueOf(s).toString() + ")";
+                return "java.lang.Integer.valueOf(" + Generator.quote(s) + ")";
             }
         }
     }
@@ -596,10 +596,10 @@ public class JspUtil {
                     + s + ", java.lang.Short.class)";
         } else {
             if (s == null || s.length() == 0) {
-                return "new java.lang.Short((short) 0)";
+                return "java.lang.Short.valueOf((short) 0)";
             } else {
                 // Detect format error at translation time
-                return "new java.lang.Short(\"" + Short.valueOf(s).toString() 
+ "\")";
+                return "java.lang.Short.valueOf(" + Generator.quote(s) + ")";
             }
         }
     }
@@ -624,10 +624,10 @@ public class JspUtil {
                     + s + ", java.lang.Long.class)";
         } else {
             if (s == null || s.length() == 0) {
-                return "new java.lang.Long(0)";
+                return "java.lang.Long.valueOf(0)";
             } else {
                 // Detect format error at translation time
-                return "new java.lang.Long(" + Long.valueOf(s).toString() + 
"l)";
+                return "java.lang.Long.valueOf(" + Generator.quote(s) + ")";
             }
         }
     }
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index a1a4a84..6ebb0df 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -215,6 +215,12 @@
         a warning will be logged and the latest supported version will used.
         (markt)
       </add>
+      <fix>
+        <bug>65377</bug>: Update the Java code generation for JSPs not to use
+        the boxed primitive constructors as they have been deprecated in Java 9
+        and marked for future removal in Java 16. <code>valueOf()</code> is now
+        used instead. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="WebSocket">

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to