This is an automated email from the ASF dual-hosted git repository.

zhaojinchao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new ae722dbfedb Compatible with null databaseName on create database 
(#23817)
ae722dbfedb is described below

commit ae722dbfedb377561b12e8b150b35cc12485a2e8
Author: Hongsheng Zhong <[email protected]>
AuthorDate: Mon Jan 30 10:27:47 2023 +0800

    Compatible with null databaseName on create database (#23817)
---
 .../shardingsphere/infra/metadata/ShardingSphereMetaData.java    | 2 +-
 .../infra/metadata/ShardingSphereMetaDataTest.java               | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java
index 368b3399502..11c8f301bc6 100644
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java
@@ -88,7 +88,7 @@ public final class ShardingSphereMetaData {
      * @return meta data database
      */
     public ShardingSphereDatabase getDatabase(final String databaseName) {
-        return databases.get(databaseName.toLowerCase());
+        return null != databaseName ? 
databases.get(databaseName.toLowerCase()) : null;
     }
     
     /**
diff --git 
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java
 
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java
index c6a625f78b2..20c1c32a12a 100644
--- 
a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java
+++ 
b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java
@@ -40,7 +40,9 @@ import java.util.Properties;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.mockStatic;
@@ -107,4 +109,11 @@ public final class ShardingSphereMetaDataTest {
                 mock(DataSourceProvidedDatabaseConfiguration.class), new 
ConfigurationProperties(new Properties()), mock(InstanceContext.class));
         assertNotNull(actual.getSchema("foo_db"));
     }
+    
+    @Test
+    public void assertNullDatabaseName() {
+        ShardingSphereMetaData metaData = new 
ShardingSphereMetaData(Collections.emptyMap(), null, new 
ConfigurationProperties(new Properties()));
+        assertFalse(metaData.containsDatabase(null));
+        assertNull(metaData.getDatabase(null));
+    }
 }

Reply via email to