From accf9c86d8e14e302a57bb3fead1146b20cb626a Mon Sep 17 00:00:00 2001 From: rusher Date: Tue, 20 Feb 2018 00:50:44 +0100 Subject: [PATCH] [misc] merge correction for 1.6 compatibility --- .../java/org/mariadb/jdbc/MariaDbClob.java | 12 ++-- .../gssapi/StandardGssapiAuthentication.java | 2 +- src/test/java/org/mariadb/jdbc/BlobTest.java | 23 ++++---- .../java/org/mariadb/jdbc/CollationTest.java | 3 +- .../mariadb/jdbc/PreparedStatementTest.java | 55 ++++++++++--------- .../java/org/mariadb/jdbc/ResultSetTest.java | 11 +++- 6 files changed, 60 insertions(+), 46 deletions(-) diff --git a/src/main/java/org/mariadb/jdbc/MariaDbClob.java b/src/main/java/org/mariadb/jdbc/MariaDbClob.java index da4a8d37d..cf3106c55 100644 --- a/src/main/java/org/mariadb/jdbc/MariaDbClob.java +++ b/src/main/java/org/mariadb/jdbc/MariaDbClob.java @@ -188,7 +188,7 @@ private int utf8Position(int charPosition) { if (byteValue < 0x80) { pos += 1; } else if (byteValue < 0xC2) { - throw new UncheckedIOException("invalid UTF8",new CharacterCodingException()); + throw new RuntimeException("invalid UTF8"); } else if (byteValue < 0xE0) { pos += 2; } else if (byteValue < 0xF0) { @@ -196,7 +196,7 @@ private int utf8Position(int charPosition) { } else if (byteValue < 0xF8) { pos += 4; } else { - throw new UncheckedIOException("invalid UTF8",new CharacterCodingException()); + throw new RuntimeException("invalid UTF8"); } } return pos; @@ -235,7 +235,7 @@ public long length() { if (byteValue < 0x80) { i += 1; } else if (byteValue < 0xC2) { - throw new UncheckedIOException("invalid UTF8",new CharacterCodingException()); + throw new RuntimeException("invalid UTF8"); } else if (byteValue < 0xE0) { i += 2; } else if (byteValue < 0xF0) { @@ -243,7 +243,7 @@ public long length() { } else if (byteValue < 0xF8) { i += 4; } else { - throw new UncheckedIOException("invalid UTF8",new CharacterCodingException()); + throw new RuntimeException("invalid UTF8"); } len++; } @@ -258,7 +258,7 @@ public void truncate(final long len) throws SQLException { if (byteValue < 0x80) { pos += 1; } else if (byteValue < 0xC2) { - throw new UncheckedIOException("invalid UTF8",new CharacterCodingException()); + throw new RuntimeException("invalid UTF8"); } else if (byteValue < 0xE0) { pos += 2; } else if (byteValue < 0xF0) { @@ -266,7 +266,7 @@ public void truncate(final long len) throws SQLException { } else if (byteValue < 0xF8) { pos += 4; } else { - throw new UncheckedIOException("invalid UTF8",new CharacterCodingException()); + throw new RuntimeException("invalid UTF8"); } } length = pos - offset; diff --git a/src/main/java/org/mariadb/jdbc/internal/com/send/gssapi/StandardGssapiAuthentication.java b/src/main/java/org/mariadb/jdbc/internal/com/send/gssapi/StandardGssapiAuthentication.java index f82e37766..1b0197f6e 100644 --- a/src/main/java/org/mariadb/jdbc/internal/com/send/gssapi/StandardGssapiAuthentication.java +++ b/src/main/java/org/mariadb/jdbc/internal/com/send/gssapi/StandardGssapiAuthentication.java @@ -96,7 +96,7 @@ public void authenticate(final PacketOutputStream writer, final String serverPri } jaasConfFile.deleteOnExit(); } catch (final IOException ex) { - throw new UncheckedIOException(ex); + throw new RuntimeException(ex); } System.setProperty("java.security.auth.login.config", jaasConfFile.getCanonicalPath()); diff --git a/src/test/java/org/mariadb/jdbc/BlobTest.java b/src/test/java/org/mariadb/jdbc/BlobTest.java index 69fe764e3..48ebc4f16 100644 --- a/src/test/java/org/mariadb/jdbc/BlobTest.java +++ b/src/test/java/org/mariadb/jdbc/BlobTest.java @@ -500,7 +500,7 @@ public void blobDeserializationFilter() throws Exception { } } - private void blobDeserializationFilterInternal(boolean addFilter, int filterSize) throws Exception { + private void blobDeserializationFilterInternal(boolean addFilter, final int filterSize) throws Exception { Assume.assumeTrue(System.getProperty("java.version").startsWith("9.")); byte[] bb = new byte[1000]; for (int i = 0; i < 1000; i++) { @@ -535,15 +535,18 @@ private void blobDeserializationFilterInternal(boolean addFilter, int filterSize ClassLoader cl = BlobTest.class.getClassLoader(); Class objectInputFilterClass = Class.forName("java.io.ObjectInputFilter"); - Object objectInputFilterImpl = Proxy.newProxyInstance(cl, new Class[] {objectInputFilterClass}, (proxy, method, args) -> { - Class filterInfoClass = Class.forName("java.io.ObjectInputFilter$FilterInfo"); - Method arrayLengthMethod = filterInfoClass.getDeclaredMethod("arrayLength"); - Long arrayLength = (Long) arrayLengthMethod.invoke(args[0]); - Class statusClass = Class.forName("java.io.ObjectInputFilter$Status"); - Field rejected = statusClass.getField("REJECTED"); - Field allowed = statusClass.getField("ALLOWED"); - if (arrayLength > filterSize) return rejected.get(null); - return allowed.get(null); + Object objectInputFilterImpl = Proxy.newProxyInstance(cl, new Class[]{objectInputFilterClass}, new InvocationHandler() { + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + Class filterInfoClass = Class.forName("java.io.ObjectInputFilter$FilterInfo"); + Method arrayLengthMethod = filterInfoClass.getDeclaredMethod("arrayLength"); + Long arrayLength = (Long) arrayLengthMethod.invoke(args[0]); + Class statusClass = Class.forName("java.io.ObjectInputFilter$Status"); + Field rejected = statusClass.getField("REJECTED"); + Field allowed = statusClass.getField("ALLOWED"); + if (arrayLength > filterSize) return rejected.get(null); + return allowed.get(null); + } }); Method setObjectInputFilterMethod = ObjectInputStream.class.getDeclaredMethod("setObjectInputFilter", objectInputFilterClass); diff --git a/src/test/java/org/mariadb/jdbc/CollationTest.java b/src/test/java/org/mariadb/jdbc/CollationTest.java index 295ee3cc2..c2e3d8f9e 100644 --- a/src/test/java/org/mariadb/jdbc/CollationTest.java +++ b/src/test/java/org/mariadb/jdbc/CollationTest.java @@ -240,7 +240,8 @@ public void insertAndSelectShouldBothUseLatin1Encoding() throws SQLException { public void languageCasing() throws SQLException { Locale currentLocal = Locale.getDefault(); createTable("languageCasing", "ID int, id2 int"); - try (Statement statement = sharedConnection.createStatement()) { + try { + Statement statement = sharedConnection.createStatement(); statement.execute("INSERT INTO languageCasing values (1,2)"); ResultSet rs = statement.executeQuery("SELECT * FROM languageCasing"); diff --git a/src/test/java/org/mariadb/jdbc/PreparedStatementTest.java b/src/test/java/org/mariadb/jdbc/PreparedStatementTest.java index 67194daf1..3dc9785b0 100644 --- a/src/test/java/org/mariadb/jdbc/PreparedStatementTest.java +++ b/src/test/java/org/mariadb/jdbc/PreparedStatementTest.java @@ -545,35 +545,38 @@ public void testInsertSelectBulk() throws SQLException { cancelForVersion(10, 3, 3); cancelForVersion(10, 3, 4); - try (Statement statement = sharedConnection.createStatement()) { - statement.execute("DROP TABLE IF EXISTS myTable"); - statement.execute("CREATE TABLE myTable(v1 varchar(10), v2 varchar(10), v3 varchar(10), v4 varchar(10))"); - - String[][] val = {{null, "b1", "c1", "d1"}, - {"a2", null, "c2", "d2"}, - {"a3", "b3", null, "d3"}, - {"a4", "b4", "c4", null}, - {"a5", "b5", "c5", "d5"}}; - try (PreparedStatement preparedStatement = sharedConnection.prepareStatement( - "INSERT INTO myTable VALUES (?, ?, ?, ?)")) { - for (int i = 0; i < val.length; i++) { - for (int j = 0; j < 4; j++) { - preparedStatement.setString(j + 1, val[i][j]); - } - preparedStatement.addBatch(); + Statement statement = sharedConnection.createStatement(); + statement.execute("DROP TABLE IF EXISTS myTable"); + statement.execute("CREATE TABLE myTable(v1 varchar(10), v2 varchar(10), v3 varchar(10), v4 varchar(10))"); + + String[][] val = {{null, "b1", "c1", "d1"}, + {"a2", null, "c2", "d2"}, + {"a3", "b3", null, "d3"}, + {"a4", "b4", "c4", null}, + {"a5", "b5", "c5", "d5"}}; + PreparedStatement preparedStatement = null; + try { + preparedStatement = sharedConnection.prepareStatement( + "INSERT INTO myTable VALUES (?, ?, ?, ?)"); + for (int i = 0; i < val.length; i++) { + for (int j = 0; j < 4; j++) { + preparedStatement.setString(j + 1, val[i][j]); } - preparedStatement.executeBatch(); + preparedStatement.addBatch(); } + preparedStatement.executeBatch(); + } finally { + preparedStatement.close(); + } - ResultSet rs = statement.executeQuery("SELECT * from myTable"); - for (int i = 0; i < val.length; i++) { - assertTrue(rs.next()); - for (int j = 0; j < 4; j++) { - if (val[i][j] == null) { - assertNull(rs.getString(j + 1)); - } else { - assertEquals(val[i][j], rs.getString(j + 1)); - } + ResultSet rs = statement.executeQuery("SELECT * from myTable"); + for (int i = 0; i < val.length; i++) { + assertTrue(rs.next()); + for (int j = 0; j < 4; j++) { + if (val[i][j] == null) { + assertNull(rs.getString(j + 1)); + } else { + assertEquals(val[i][j], rs.getString(j + 1)); } } } diff --git a/src/test/java/org/mariadb/jdbc/ResultSetTest.java b/src/test/java/org/mariadb/jdbc/ResultSetTest.java index 4859d8213..d7678a4dd 100644 --- a/src/test/java/org/mariadb/jdbc/ResultSetTest.java +++ b/src/test/java/org/mariadb/jdbc/ResultSetTest.java @@ -1168,17 +1168,24 @@ public void invisibleColumn() throws SQLException { Statement stmt = sharedConnection.createStatement(); stmt.execute("INSERT INTO invisible(x,y) VALUES (1,2)"); - try (PreparedStatement preparedStatement = sharedConnection.prepareStatement("SELECT * FROM invisible WHERE x = ?")) { + PreparedStatement preparedStatement = null; + try { + preparedStatement = sharedConnection.prepareStatement("SELECT * FROM invisible WHERE x = ?"); ResultSetMetaData resultSetMetaData = preparedStatement.getMetaData(); Assert.assertEquals(1, resultSetMetaData.getColumnCount()); Assert.assertEquals("x", resultSetMetaData.getColumnName(1)); + } finally { + preparedStatement.close(); } - try (PreparedStatement preparedStatement = sharedConnection.prepareStatement("SELECT x,z FROM invisible WHERE x = ?")) { + try { + preparedStatement = sharedConnection.prepareStatement("SELECT x,z FROM invisible WHERE x = ?"); ResultSetMetaData resultSetMetaData = preparedStatement.getMetaData(); Assert.assertEquals(2, resultSetMetaData.getColumnCount()); Assert.assertEquals("x", resultSetMetaData.getColumnName(1)); Assert.assertEquals("z", resultSetMetaData.getColumnName(2)); + } finally { + preparedStatement.close(); } }