You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by za...@apache.org on 2023/01/10 12:50:02 UTC
[calcite-avatica] branch main updated: [CALCITE-5120] UnregisteredDriver#connect should throw SQLException, not NullPointerException, if url is null
This is an automated email from the ASF dual-hosted git repository.
zabetak pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite-avatica.git
The following commit(s) were added to refs/heads/main by this push:
new ac47eb619 [CALCITE-5120] UnregisteredDriver#connect should throw SQLException, not NullPointerException, if url is null
ac47eb619 is described below
commit ac47eb619575b13a92b16574d2f4e6af51139e05
Author: zoudan <zo...@bytedance.com>
AuthorDate: Mon Jan 9 15:22:37 2023 +0800
[CALCITE-5120] UnregisteredDriver#connect should throw SQLException, not NullPointerException, if url is null
Close apache/calcite-avatica#204
---
.../apache/calcite/avatica/UnregisteredDriver.java | 3 +
.../calcite/avatica/UnregisteredDriverTest.java | 66 ++++++++++++++++++++++
2 files changed, 69 insertions(+)
diff --git a/core/src/main/java/org/apache/calcite/avatica/UnregisteredDriver.java b/core/src/main/java/org/apache/calcite/avatica/UnregisteredDriver.java
index 4118fd7f5..a60190c44 100644
--- a/core/src/main/java/org/apache/calcite/avatica/UnregisteredDriver.java
+++ b/core/src/main/java/org/apache/calcite/avatica/UnregisteredDriver.java
@@ -141,6 +141,9 @@ public abstract class UnregisteredDriver implements java.sql.Driver {
}
public boolean acceptsURL(String url) throws SQLException {
+ if (url == null) {
+ throw new SQLException("url can not be null!");
+ }
return url.startsWith(getConnectStringPrefix());
}
diff --git a/core/src/test/java/org/apache/calcite/avatica/UnregisteredDriverTest.java b/core/src/test/java/org/apache/calcite/avatica/UnregisteredDriverTest.java
new file mode 100644
index 000000000..e5958f0ce
--- /dev/null
+++ b/core/src/test/java/org/apache/calcite/avatica/UnregisteredDriverTest.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.avatica;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import java.sql.Driver;
+import java.sql.SQLException;
+import java.util.Properties;
+
+/**
+ * Test class for {@link UnregisteredDriver}.
+ */
+public class UnregisteredDriverTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Test public void testAcceptsURLWithNull() throws SQLException {
+ final Driver driver = new UnregisteredTestDriver();
+ thrown.expect(SQLException.class);
+ thrown.expectMessage("url can not be null!");
+ driver.acceptsURL(null);
+ }
+
+ @Test public void testConnectWithNullURL() throws SQLException {
+ final Driver driver = new UnregisteredTestDriver();
+ thrown.expect(SQLException.class);
+ thrown.expectMessage("url can not be null!");
+ driver.connect(null, new Properties());
+ }
+
+ private static final class UnregisteredTestDriver extends UnregisteredDriver {
+
+ @Override
+ protected DriverVersion createDriverVersion() {
+ return null;
+ }
+
+ @Override
+ protected String getConnectStringPrefix() {
+ return null;
+ }
+
+ @Override
+ public Meta createMeta(AvaticaConnection connection) {
+ return null;
+ }
+ }
+}