Issue 1:
Bug Report

For English only, other languages will not accept.

Before report a bug, make sure you have:

Searched open and closed GitHub issues.

Read documentation: ShardingSphere Doc.

Please pay attention on issues you submitted, because we maybe need more details.

If no response anymore and we cannot reproduce it on current information, we will close it.

Please answer these questions before submitting your issue. Thanks!

Which version of ShardingSphere did you use?

5.0.0-RC1-SNAPSHOT

Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?

ShardingSphere-Proxy

Expected behavior

CREATE TABLE executed correctly.

Actual behavior

Either

mysql> CREATE TABLE `t_encrypt` ( `user_id` bigint DEFAULT NULL, `order_id` bigint DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
ERROR 19999 (C1999): 9Unknown exception: [null]

or

mysql> CREATE TABLE `t_encrypt` (
-> `user_id` bigint DEFAULT NULL,
-> `order_id` bigint DEFAULT NULL,
-> `user_cipher` varchar(100) DEFAULT NULL,
-> `order_cipher` varchar(100) DEFAULT NULL
-> ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
ERROR 19999 (C1999): 9Unknown exception: [null]

Reason analyze (If you can)

[INFO ] 2021-03-03 18:23:47.852 [ShardingSphere-Command-2] ShardingSphere-SQL - Logic SQL: CREATE TABLE `t_encrypt` ( `user_id` bigint DEFAULT NULL, `order_id` bigint DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
[INFO ] 2021-03-03 18:23:47.852 [ShardingSphere-Command-2] ShardingSphere-SQL - SQLStatement: MySQLCreateTableStatement(isNotExisted=false)
[INFO ] 2021-03-03 18:23:47.852 [ShardingSphere-Command-2] ShardingSphere-SQL - Actual SQL: dataSource ::: CREATE TABLE `t_encrypt` ( `user_id` bigint DEFAULT NULL, `order_id` bigint DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
[ERROR] 2021-03-03 18:23:47.914 [ShardingSphere-Command-2] o.a.s.p.f.c.CommandExecutorTask - Exception occur:
java.util.NoSuchElementException: null
at java.util.ArrayList$Itr.next(ArrayList.java:862)
at org.apache.shardingsphere.infra.metadata.schema.refresher.type.CreateTableStatementSchemaRefresher.refresh(CreateTableStatementSchemaRefresher.java:50)
at org.apache.shardingsphere.infra.metadata.schema.refresher.type.CreateTableStatementSchemaRefresher.refresh(CreateTableStatementSchemaRefresher.java:37)
at org.apache.shardingsphere.infra.metadata.engine.MetadataRefreshEngine.refreshSchema(MetadataRefreshEngine.java:75)
at org.apache.shardingsphere.infra.metadata.engine.MetadataRefreshEngine.refresh(MetadataRefreshEngine.java:64)
at org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngine.refreshMetadata(DatabaseCommunicationEngine.java:190)
at org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngine.execute(DatabaseCommunicationEngine.java:113)
at org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngine.execute(DatabaseCommunicationEngine.java:101)
at org.apache.shardingsphere.proxy.backend.text.data.impl.SchemaAssignedDatabaseBackendHandler.execute(SchemaAssignedDatabaseBackendHandler.java:55)
at org.apache.shardingsphere.proxy.frontend.mysql.command.query.text.query.MySQLComQueryPacketExecutor.execute(MySQLComQueryPacketExecutor.java:57)
at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.executeCommand(CommandExecutorTask.java:93)
at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.run(CommandExecutorTask.java:71)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

And

[INFO ] 2021-03-03 18:13:11.271 [ShardingSphere-Command-1] ShardingSphere-SQL - Logic SQL: CREATE TABLE `t_encrypt` (
`user_id` bigint DEFAULT NULL,
`order_id` bigint DEFAULT NULL,
`user_cipher` varchar(100) DEFAULT NULL,
`order_cipher` varchar(100) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
[INFO ] 2021-03-03 18:13:11.271 [ShardingSphere-Command-1] ShardingSphere-SQL - SQLStatement: MySQLCreateTableStatement(isNotExisted=false)
[INFO ] 2021-03-03 18:13:11.271 [ShardingSphere-Command-1] ShardingSphere-SQL - Actual SQL: dataSource ::: CREATE TABLE `t_encrypt` (
`user_id` bigint DEFAULT NULL,
`order_id` bigint DEFAULT NULL,
`user_cipher` varchar(100) DEFAULT NULL,
`order_cipher` varchar(100) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
[ERROR] 2021-03-03 18:13:11.383 [ShardingSphere-Command-1] o.a.s.p.f.c.CommandExecutorTask - Exception occur:
java.util.NoSuchElementException: null
at java.util.ArrayList$Itr.next(ArrayList.java:862)
at org.apache.shardingsphere.infra.metadata.schema.refresher.type.CreateTableStatementSchemaRefresher.refresh(CreateTableStatementSchemaRefresher.java:50)
at org.apache.shardingsphere.infra.metadata.schema.refresher.type.CreateTableStatementSchemaRefresher.refresh(CreateTableStatementSchemaRefresher.java:37)
at org.apache.shardingsphere.infra.metadata.engine.MetadataRefreshEngine.refreshSchema(MetadataRefreshEngine.java:75)
at org.apache.shardingsphere.infra.metadata.engine.MetadataRefreshEngine.refresh(MetadataRefreshEngine.java:64)
at org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngine.refreshMetadata(DatabaseCommunicationEngine.java:190)
at org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngine.execute(DatabaseCommunicationEngine.java:113)
at org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngine.execute(DatabaseCommunicationEngine.java:101)
at org.apache.shardingsphere.proxy.backend.text.data.impl.SchemaAssignedDatabaseBackendHandler.execute(SchemaAssignedDatabaseBackendHandler.java:55)
at org.apache.shardingsphere.proxy.frontend.mysql.command.query.text.query.MySQLComQueryPacketExecutor.execute(MySQLComQueryPacketExecutor.java:57)
at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.executeCommand(CommandExecutorTask.java:93)
at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.run(CommandExecutorTask.java:71)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

config-encrypt.yaml

schemaName: encrypt_db

dataSource:
url: jdbc:mysql://127.0.0.1:3306/demo_ds?serverTimezone=UTC&useSSL=false
username: root
password:
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50

rules:
- !ENCRYPT
encryptors:
aes_encryptor:
type: AES
props:
aes-key-value: 123456abc
md5_encryptor:
type: MD5
tables:
t_encrypt:
columns:
user_id:
cipherColumn: user_cipher
encryptorName: md5_encryptor
order_id:
cipherColumn: order_cipher
encryptorName: md5_encryptor

server.yaml

authentication:
users:
root:
password: root
hostname: '%'
sharding:
password: sharding

props:
max-connections-size-per-query: 1
executor-size: 16 # Infinite by default.
proxy-frontend-flush-threshold: 128 # The default value is 128.
# LOCAL: Proxy will run with LOCAL transaction.
# XA: Proxy will run with XA transaction.
# BASE: Proxy will run with B.A.S.E transaction.
proxy-transaction-type: LOCAL
xa-transaction-manager-type: Atomikos
proxy-opentracing-enabled: false
proxy-hint-enabled: false
query-with-cipher-column: true
sql-show: true
check-table-metadata-enabled: false
lock-wait-timeout-milliseconds: 50000 # The maximum time to wait for a lock

Example codes for reproduce this issue (such as a github link).

Issue 2:
Please answer these questions before submitting your issue. Thanks!

使用DataSourceUtil的编程方式连接数据源

`

@configuration

@MapperScan("com.knowbox.kms.tiku.dao")

public class MyBatisConfig {

private static final String URL_PREFIX = "jdbc:mysql://127.0.0.1:3306/";

private static final String USER_NAME = "test";

private static final String PASSWORD = "test";

@Bean
@Primary
public static SqlSessionFactoryBean createSqlSessionFactoryBean() throws SQLException, IOException {

SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
// 设置mybatis configuration 扫描路径
sqlSessionFactoryBean.setConfigLocation(new ClassPathResource("META-INF/mybatis-config.xml"));

// 添加mapper 扫描路径
PathMatchingResourcePatternResolver pathMatchingResourcePatternResolver = new PathMatchingResourcePatternResolver();
sqlSessionFactoryBean.setMapperLocations(pathMatchingResourcePatternResolver.getResources(ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + "/META-INF/mapper/*.xml"));

// 设置datasource
DataSource dataSource = getMasterSlaveDataSource();
sqlSessionFactoryBean.setDataSource(dataSource);
return sqlSessionFactoryBean;
}

private static DataSource getMasterSlaveDataSource() throws SQLException {
MasterSlaveRuleConfiguration masterSlaveRuleConfig = new MasterSlaveRuleConfiguration();
masterSlaveRuleConfig.setName("ds_master_slave");
masterSlaveRuleConfig.setMasterDataSourceName("ds_master");
masterSlaveRuleConfig.setSlaveDataSourceNames(Arrays.asList("ds_slave_0", "ds_slave_1"));
return MasterSlaveDataSourceFactory.createDataSource(createDataSourceMap(), masterSlaveRuleConfig, new ConcurrentHashMap<>());
}

private static Map<String, DataSource> createDataSourceMap() {
final Map<String, DataSource> result = new HashMap<>(3, 1);
result.put("ds_master", createDataSource("dev"));
result.put("ds_slave_0", createDataSource("dev"));
result.put("ds_slave_1", createDataSource("dev"));
return result;
}

private static DataSource createDataSource(final String dataSourceName) {

DruidDataSource result = new DruidDataSource();
result.setDriverClassName(com.mysql.jdbc.Driver.class.getName());
result.setUrl(URL_PREFIX + dataSourceName);
result.setUsername(USER_NAME);
result.setPassword(PASSWORD);
return result;
}

`

Which version of Sharding-Jdbc do you using?（您使用的Sharding-Jdbc版本为？）

sharing jdbc 2.0.3

druid 1.1.9

Expected behavior （您预期的结果是）

Actual behavior （实际运行的结果是）

Caused by: java.lang.NullPointerException: null

at io.shardingjdbc.spring.boot.SpringBootConfiguration.setDataSourceMap(SpringBootConfiguration.java:55) ~[sharding-jdbc-core-spring-boot-starter-2.0.3.jar:na]

at io.shardingjdbc.spring.boot.SpringBootConfiguration.setEnvironment(SpringBootConfiguration.java:49) ~[sharding-jdbc-core-spring-boot-starter-2.0.3.jar:na]

at org.springframework.context.support.ApplicationContextAwareProcessor.invokeAwareInterfaces(ApplicationContextAwareProcessor.java:106) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]

at org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:97) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:409) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1620) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]

... 15 common frames omitted