Changeset: b6d113ee35ae for monetdb-java
URL: https://dev.monetdb.org/hg/monetdb-java/rev/b6d113ee35ae
Modified Files:
        SQLSTATEs
        src/main/java/org/monetdb/jdbc/MonetPreparedStatement.java
        src/main/java/org/monetdb/jdbc/MonetResultSet.java
        src/main/java/org/monetdb/jdbc/types/URL.java
        tests/JDBC_API_Tester.java
Branch: default
Log Message:

Fixed javac version 20 compiler warnings.
The java.net.URL(String) constructor is deprecated since version 20.
It needs to be replaced by: java.net.URI(String).toURL() and some extra 
Exception catching.


diffs (184 lines):

diff --git a/SQLSTATEs b/SQLSTATEs
--- a/SQLSTATEs
+++ b/SQLSTATEs
@@ -24,9 +24,9 @@ 0AM34 Java generics not supported
 
 22M28 invalid BLOB format
 22M29 invalid inet format
-22M30 invalid url format
-22M31 invalid uuid format
-22M32 invalid json format
+22M30 invalid URL format
+22M31 invalid UUID format
+22M32 invalid JSON format
 
 2BM37 dependent objects still exist
 2DM30 autocommit mode active
diff --git a/src/main/java/org/monetdb/jdbc/MonetPreparedStatement.java 
b/src/main/java/org/monetdb/jdbc/MonetPreparedStatement.java
--- a/src/main/java/org/monetdb/jdbc/MonetPreparedStatement.java
+++ b/src/main/java/org/monetdb/jdbc/MonetPreparedStatement.java
@@ -1887,8 +1887,10 @@ public class MonetPreparedStatement
                                                try {
                                                        // also check if x 
represents a valid url string to prevent
                                                        // failing exec #(..., 
...) calls which destroy the prepared statement, see bug 6351
-                                                       java.net.URL url_obj = 
new java.net.URL(x);
-                                               } catch 
(java.net.MalformedURLException mue) {
+                                                       // Note: as of Java 
version 20 java.net.URL(String) constructor is deprecated.
+                                                       // 
https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/net/URL.html#%3Cinit%3E(java.lang.String)
+                                                       java.net.URL url_obj = 
new java.net.URI(x).toURL();
+                                               } catch 
(java.net.URISyntaxException | java.net.MalformedURLException mue) {
                                                        throw new 
SQLDataException("Conversion of string: " + x + " to parameter data type " + 
paramMonetdbType + " failed. " + mue.getMessage(), "22M30");
                                                }
                                                castprefix = "url ";
diff --git a/src/main/java/org/monetdb/jdbc/MonetResultSet.java 
b/src/main/java/org/monetdb/jdbc/MonetResultSet.java
--- a/src/main/java/org/monetdb/jdbc/MonetResultSet.java
+++ b/src/main/java/org/monetdb/jdbc/MonetResultSet.java
@@ -2463,9 +2463,11 @@ public class MonetResultSet
                        }
                        lastReadWasNull = false;
                        try {
-                               return new URL(val);
-                       } catch (java.net.MalformedURLException e) {
-                               throw new SQLException(e.getMessage(), "M1M05");
+                               // Note: as of Java version 20 
java.net.URL(String) constructor is deprecated.
+                               // 
https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/net/URL.html#%3Cinit%3E(java.lang.String)
+                               return new java.net.URI(val).toURL();
+                       } catch (java.net.URISyntaxException | 
java.net.MalformedURLException e) {
+                               throw new SQLException(e.getMessage(), "22M30");
                        }
                } catch (IndexOutOfBoundsException e) {
                        throw newSQLInvalidColumnIndexException(columnIndex);
diff --git a/src/main/java/org/monetdb/jdbc/types/URL.java 
b/src/main/java/org/monetdb/jdbc/types/URL.java
--- a/src/main/java/org/monetdb/jdbc/types/URL.java
+++ b/src/main/java/org/monetdb/jdbc/types/URL.java
@@ -8,6 +8,7 @@
 
 package org.monetdb.jdbc.types;
 
+import java.sql.SQLDataException;
 import java.sql.SQLException;
 
 /**
@@ -15,13 +16,23 @@ import java.sql.SQLException;
  * It represents an URL, that is, a well-formed string conforming to RFC2396.
  */
 public final class URL implements java.sql.SQLData {
+       /** String url */
        private String url;
 
+       /**
+        * String getSQLTypeName()
+        * @return String the type name
+        */
        @Override
        public String getSQLTypeName() {
                return "url";
        }
 
+       /**
+        * void readSQL(final java.sql.SQLInput stream, final String typeName)
+        * @param stream a java.sql.SQLInput stream
+        * @param typeName the type name
+        */
        @Override
        public void readSQL(final java.sql.SQLInput stream, final String 
typeName) throws SQLException {
                if (!"url".equals(typeName))
@@ -29,16 +40,29 @@ public final class URL implements java.s
                url = stream.readString();
        }
 
+       /**
+        * void writeSQL(final java.sql.SQLOutput stream)
+        * @param stream a java.sql.SQLOutput stream
+        */
        @Override
        public void writeSQL(final java.sql.SQLOutput stream) throws 
SQLException {
                stream.writeString(url);
        }
 
+       /**
+        * String toString()
+        * @return String the url string
+        */
        @Override
        public String toString() {
                return url;
        }
 
+       /**
+        * void fromString(final String newurl)
+        * @param newurl the new url string
+        * @throws Exception when conversion of newurl string to URI or URL 
object fails
+        */
        public void fromString(final String newurl) throws Exception {
                if (newurl == null) {
                        url = newurl;
@@ -46,23 +70,36 @@ public final class URL implements java.s
                }
 
                // parse the newurl on validity
-               new java.net.URL(newurl);
-               // if above doesn't fail (throws an Exception), it is fine
+               // Note: as of Java version 20 java.net.URL(String) constructor 
is deprecated.
+               // 
https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/net/URL.html#%3Cinit%3E(java.lang.String)
+               new java.net.URI(newurl).toURL();
+               // if above doesn't fail (throws an java.net.URISyntaxException 
| java.net.MalformedURLException), it is fine
                url = newurl;
        }
 
-       public java.net.URL getURL() throws SQLException {
+       /**
+        * java.net.URL getURL()
+        * @return URL an url object
+        * @throws SQLDataException when conversion of url string to URL object 
fails
+        */
+       public java.net.URL getURL() throws SQLDataException {
                if (url == null)
                        return null;
 
                try {
-                       return new java.net.URL(url);
-               } catch (java.net.MalformedURLException mue) {
-                       throw new java.sql.SQLDataException("data is not a 
valid URL: " + mue.getMessage(), "22M30");
+                       // Note: as of java 20 java.net.URL(String) constructor 
is deprecated.
+                       // 
https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/net/URL.html#%3Cinit%3E(java.lang.String)
+                       return new java.net.URI(url).toURL();
+               } catch (java.net.URISyntaxException | 
java.net.MalformedURLException mue) {
+                       throw new SQLDataException("data is not a valid URL: " 
+ mue.getMessage(), "22M30");
                }
        }
 
-       public void setURL(final java.net.URL nurl) throws Exception {
+       /**
+        * void setURL(final java.net.URL nurl)
+        * @param nurl a java.net.URL object
+        */
+       public void setURL(final java.net.URL nurl) {
                url = nurl.toString();
        }
 }
diff --git a/tests/JDBC_API_Tester.java b/tests/JDBC_API_Tester.java
--- a/tests/JDBC_API_Tester.java
+++ b/tests/JDBC_API_Tester.java
@@ -3245,8 +3245,8 @@ final public class JDBC_API_Tester {
                        cstmt.setDouble(2, 3.02);
                        cstmt.setString(4, "Tree");
                        try {
-                               cstmt.setURL(6, new 
java.net.URL("https://www.monetdb.org/";));
-                       } catch (java.net.MalformedURLException mfue) {
+                               cstmt.setURL(6, new 
java.net.URI("https://www.monetdb.org/";).toURL());
+                       } catch (java.net.URISyntaxException | 
java.net.MalformedURLException mfue) {
                                sb.append("Invalid URL: 
").append(mfue.getMessage()).append("\n");
                        }
                        cstmt.execute();
@@ -5776,8 +5776,8 @@ final public class JDBC_API_Tester {
                        pstmt.setObject(3, "[3.1415E-06]");
                        pstmt.setNull(4, 0);
                        try {
-                               pstmt.setURL(5, new 
java.net.URL("https://www.cwi.nl/";));
-                       } catch (java.net.MalformedURLException mfe) {
+                               pstmt.setURL(5, new 
java.net.URI("https://www.cwi.nl/";).toURL());
+                       } catch (java.net.URISyntaxException | 
java.net.MalformedURLException mfe) {
                                sb.append(mfe).append("\n");
                        }
                        sb.append("Inserting row ").append(row).append("\n");
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to