You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2021/06/25 12:16:33 UTC

[tomcat] branch 8.5.x updated: BZ 54377 - Update code generation to use valueOf for boxed primitives

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

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


The following commit(s) were added to refs/heads/8.5.x by this push:
     new 7f74e96  BZ 54377 - Update code generation to use valueOf for boxed primitives
7f74e96 is described below

commit 7f74e963532192967aa516a088932c91869969d7
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 1b45ae4..55ceca6 100644
--- a/java/org/apache/jasper/compiler/JspUtil.java
+++ b/java/org/apache/jasper/compiler/JspUtil.java
@@ -456,10 +456,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) + ")";
             }
         }
     }
@@ -484,10 +484,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) + ")";
             }
         }
     }
@@ -513,11 +513,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 + ")";
             }
         }
     }
@@ -542,10 +542,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) + ")";
             }
         }
     }
@@ -570,10 +570,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) + ")";
             }
         }
     }
@@ -597,10 +597,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) + ")";
             }
         }
     }
@@ -625,10 +625,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) + ")";
             }
         }
     }
@@ -653,10 +653,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 96e1190..edfd1d2 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -203,6 +203,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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org