Changeset: 87feb93330a6 for monetdb-java
URL: https://dev.monetdb.org/hg/monetdb-java/rev/87feb93330a6
Modified Files:
        example/OnClientExample.java
        src/main/java/org/monetdb/jdbc/MonetConnection.java
        src/main/java/org/monetdb/mcl/net/MapiSocket.java
        tests/OnClientTester.java
        tests/TestRunner.java
Branch: onclient
Log Message:

Misc. changes suggested by analysis tool


diffs (248 lines):

diff --git a/example/OnClientExample.java b/example/OnClientExample.java
--- a/example/OnClientExample.java
+++ b/example/OnClientExample.java
@@ -21,7 +21,7 @@ import java.sql.*;
 public class OnClientExample {
 
        public static void main(String[] args) {
-               int status = 0;
+               int status;
                try {
                        // Ideally this would not be hardcoded..
                        final String dbUrl = 
"jdbc:monetdb://localhost:55000/banana";
diff --git a/src/main/java/org/monetdb/jdbc/MonetConnection.java 
b/src/main/java/org/monetdb/jdbc/MonetConnection.java
--- a/src/main/java/org/monetdb/jdbc/MonetConnection.java
+++ b/src/main/java/org/monetdb/jdbc/MonetConnection.java
@@ -2135,7 +2135,7 @@ public class MonetConnection
                 * @return a non-null String if the line is invalid,
                 *         or additional lines are not allowed.
                 */
-               public abstract String addLine(String line, LineType linetype);
+               String addLine(String line, LineType linetype);
 
                /**
                 * Returns whether this Response expects more lines to be added
@@ -2143,7 +2143,7 @@ public class MonetConnection
                 *
                 * @return true if a next line should be added, false otherwise
                 */
-               public abstract boolean wantsMore();
+               boolean wantsMore();
 
                /**
                 * Indicates that no more header lines will be added to this
@@ -2160,7 +2160,7 @@ public class MonetConnection
                 * Instructs the Response implementation to close and do the
                 * necessary clean up procedures.
                 */
-               public abstract void close();
+               void close();
        }
        // }}}
 
@@ -3050,7 +3050,7 @@ public class MonetConnection
                                                                        if 
(rowcount < tuplecount) {
                                                                                
if (rsresponses == null)
                                                                                
        rsresponses = new HashMap<Integer, ResultSetResponse>();
-                                                                               
rsresponses.put(Integer.valueOf(id), (ResultSetResponse) res);
+                                                                               
rsresponses.put(id, (ResultSetResponse) res);
                                                                        }
                                                                } break;
                                                                case 
StartOfHeaderParser.Q_UPDATE:
@@ -3078,7 +3078,7 @@ public class MonetConnection
                                                                        final 
int offset = sohp.getNextAsInt();
                                                                        final 
ResultSetResponse t;
                                                                        if 
(rsresponses != null)
-                                                                               
t = rsresponses.get(Integer.valueOf(id));
+                                                                               
t = rsresponses.get(id);
                                                                        else
                                                                                
t = null;
                                                                        if (t 
== null) {
@@ -3275,7 +3275,7 @@ public class MonetConnection
         * To be registered with {@link 
MonetConnection#setUploadHandler(UploadHandler)}
         */
 
-       public static interface UploadHandler {
+       public interface UploadHandler {
                /**
                 * Called if the server sends a request to read file data.
                 *
@@ -3297,7 +3297,7 @@ public class MonetConnection
         *
         * To be registered with {@link 
MonetConnection#setDownloadHandler(DownloadHandler)}
         */
-       public static interface DownloadHandler {
+       public interface DownloadHandler {
                /**
                 * Called if the server sends a request to write a file.
                 *
diff --git a/src/main/java/org/monetdb/mcl/net/MapiSocket.java 
b/src/main/java/org/monetdb/mcl/net/MapiSocket.java
--- a/src/main/java/org/monetdb/mcl/net/MapiSocket.java
+++ b/src/main/java/org/monetdb/mcl/net/MapiSocket.java
@@ -346,26 +346,32 @@ public class MapiSocket { /* cannot (yet
                                                int pos = args[i].indexOf("=");
                                                if (pos > 0) {
                                                        tmp = 
args[i].substring(0, pos);
-                                                       if 
(tmp.equals("database")) {
-                                                               tmp = 
args[i].substring(pos + 1);
-                                                               if 
(!tmp.equals(database)) {
-                                                                       
warns.add("redirect points to different database: " + tmp);
-                                                                       
setDatabase(tmp);
-                                                               }
-                                                       } else if 
(tmp.equals("language")) {
-                                                               tmp = 
args[i].substring(pos + 1);
-                                                               
warns.add("redirect specifies use of different language: " + tmp);
-                                                               
setLanguage(tmp);
-                                                       } else if 
(tmp.equals("user")) {
-                                                               tmp = 
args[i].substring(pos + 1);
-                                                               if 
(!tmp.equals(user))
-                                                                       
warns.add("ignoring different username '" + tmp + "' set by " +
-                                                                               
        "redirect, what are the security implications?");
-                                                       } else if 
(tmp.equals("password")) {
-                                                               
warns.add("ignoring different password set by redirect, " +
-                                                                               
"what are the security implications?");
-                                                       } else {
-                                                               
warns.add("ignoring unknown argument '" + tmp + "' from redirect");
+                                                       switch (tmp) {
+                                                               case "database":
+                                                                       tmp = 
args[i].substring(pos + 1);
+                                                                       if 
(!tmp.equals(database)) {
+                                                                               
warns.add("redirect points to different database: " + tmp);
+                                                                               
setDatabase(tmp);
+                                                                       }
+                                                                       break;
+                                                               case "language":
+                                                                       tmp = 
args[i].substring(pos + 1);
+                                                                       
warns.add("redirect specifies use of different language: " + tmp);
+                                                                       
setLanguage(tmp);
+                                                                       break;
+                                                               case "user":
+                                                                       tmp = 
args[i].substring(pos + 1);
+                                                                       if 
(!tmp.equals(user))
+                                                                               
warns.add("ignoring different username '" + tmp + "' set by " +
+                                                                               
                "redirect, what are the security implications?");
+                                                                       break;
+                                                               case "password":
+                                                                       
warns.add("ignoring different password set by redirect, " +
+                                                                               
        "what are the security implications?");
+                                                                       break;
+                                                               default:
+                                                                       
warns.add("ignoring unknown argument '" + tmp + "' from redirect");
+                                                                       break;
                                                        }
                                                } else {
                                                        warns.add("ignoring 
illegal argument from redirect: " + args[i]);
@@ -456,18 +462,23 @@ public class MapiSocket { /* cannot (yet
                                String pwhash = chaltok[5];
                                /* NOTE: Java doesn't support RIPEMD160 :( */
                                /* see: 
https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#MessageDigest
 */
-                               if (pwhash.equals("SHA512")) {
-                                       algo = "SHA-512";
-                               } else if (pwhash.equals("SHA384")) {
-                                       algo = "SHA-384";
-                               } else if (pwhash.equals("SHA256")) {
-                                       algo = "SHA-256";
-                               /* NOTE: Java 7 doesn't support SHA-224. Java 8 
does but we have not tested it. It is also not requested yet. */
-                               } else if (pwhash.equals("SHA1")) {
-                                       algo = "SHA-1";
-                               } else {
-                                       /* Note: MD5 has been deprecated by 
security experts and support is removed from Oct 2020 release */
-                                       throw new MCLException("Unsupported 
password hash: " + pwhash);
+                               switch (pwhash) {
+                                       case "SHA512":
+                                               algo = "SHA-512";
+                                               break;
+                                       case "SHA384":
+                                               algo = "SHA-384";
+                                               break;
+                                       case "SHA256":
+                                               algo = "SHA-256";
+                                               /* NOTE: Java 7 doesn't support 
SHA-224. Java 8 does but we have not tested it. It is also not requested yet. */
+                                               break;
+                                       case "SHA1":
+                                               algo = "SHA-1";
+                                               break;
+                                       default:
+                                               /* Note: MD5 has been 
deprecated by security experts and support is removed from Oct 2020 release */
+                                               throw new 
MCLException("Unsupported password hash: " + pwhash);
                                }
                                try {
                                        final MessageDigest md = 
MessageDigest.getInstance(algo);
@@ -822,9 +833,8 @@ public class MapiSocket {   /* cannot (yet
 
                @Override
                public void write(final byte[] b, int off, int len) throws 
IOException {
-                       int t = 0;
                        while (len > 0) {
-                               t = BLOCK - writePos;
+                               int t = BLOCK - writePos;
                                if (len > t) {
                                        System.arraycopy(b, off, block, 
writePos, t);
                                        off += t;
@@ -1066,9 +1076,8 @@ public class MapiSocket { /* cannot (yet
                @Override
                public long skip(final long n) throws IOException {
                        long skip = n;
-                       int t = 0;
                        while (skip > 0) {
-                               t = available();
+                               int t = available();
                                if (skip > t) {
                                        skip -= t;
                                        readPos += t;
diff --git a/tests/OnClientTester.java b/tests/OnClientTester.java
--- a/tests/OnClientTester.java
+++ b/tests/OnClientTester.java
@@ -53,7 +53,7 @@ public final class OnClientTester extend
                        System.exit(1);
        }
 
-       protected void prepare() throws SQLException {
+       void prepare() throws SQLException {
                execute("DROP TABLE IF EXISTS foo");
                execute("CREATE TABLE foo (i INT, t TEXT)");
        }
@@ -361,10 +361,6 @@ public final class OnClientTester extend
                        return attempts;
                }
 
-               public int countBytes() {
-                       return bytesSeen;
-               }
-
                public int lineCount() {
                        int lines = lineEndingsSeen;
                        if (startOfLine != bytesSeen)
diff --git a/tests/TestRunner.java b/tests/TestRunner.java
--- a/tests/TestRunner.java
+++ b/tests/TestRunner.java
@@ -37,7 +37,7 @@ public class TestRunner {
                        watchDog.disable();
        }
 
-       protected int runTests(String testPrefix) throws SQLException, 
NoSuchMethodException {
+       protected int runTests(String testPrefix) throws SQLException {
                int testCount = 0;
                int skippedCount = 0;
                ArrayList<String> failures = new ArrayList<>();
@@ -218,7 +218,7 @@ public class TestRunner {
                assertEq("Update count", expectedUpdateCount, updateCount);
        }
 
-       protected void expectError(String query, String expectedError) throws 
SQLException, Failure {
+       protected void expectError(String query, String expectedError) throws 
SQLException {
                try {
                        execute(query);
                } catch (SQLException e) {
@@ -306,11 +306,6 @@ public class TestRunner {
                        this.notifyAll();
                }
 
-               synchronized void kill() {
-                       started = -1;
-                       this.notifyAll();
-               }
-
                private synchronized void work() {
                        long now;
                        try {
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to