Skip to content

Commit

Permalink
[misc] merge correction for 1.6 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Feb 19, 2018
1 parent efa503a commit accf9c8
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 46 deletions.
12 changes: 6 additions & 6 deletions src/main/java/org/mariadb/jdbc/MariaDbClob.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,15 @@ 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) {
pos += 3;
} else if (byteValue < 0xF8) {
pos += 4;
} else {
throw new UncheckedIOException("invalid UTF8",new CharacterCodingException());
throw new RuntimeException("invalid UTF8");
}
}
return pos;
Expand Down Expand Up @@ -235,15 +235,15 @@ 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) {
i += 3;
} else if (byteValue < 0xF8) {
i += 4;
} else {
throw new UncheckedIOException("invalid UTF8",new CharacterCodingException());
throw new RuntimeException("invalid UTF8");
}
len++;
}
Expand All @@ -258,15 +258,15 @@ 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) {
pos += 3;
} else if (byteValue < 0xF8) {
pos += 4;
} else {
throw new UncheckedIOException("invalid UTF8",new CharacterCodingException());
throw new RuntimeException("invalid UTF8");
}
}
length = pos - offset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
23 changes: 13 additions & 10 deletions src/test/java/org/mariadb/jdbc/BlobTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/org/mariadb/jdbc/CollationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
55 changes: 29 additions & 26 deletions src/test/java/org/mariadb/jdbc/PreparedStatementTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Expand Down
11 changes: 9 additions & 2 deletions src/test/java/org/mariadb/jdbc/ResultSetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
Expand Down

0 comments on commit accf9c8

Please sign in to comment.