You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "Nilesh18398 (via GitHub)" <gi...@apache.org> on 2026/06/18 13:08:39 UTC

[I] ShardingSphereDataSourceFactory fails at runtime with NPE in StorageUnit during Spring Boot startup [shardingsphere]

Nilesh18398 opened a new issue, #38870:
URL: https://github.com/apache/shardingsphere/issues/38870

   A Spring Boot 4 / ShardingSphere 5.5.3 application compiles successfully, but fails at runtime when creating the ShardingSphere [DataSource](vscode-file://vscode-app/c:/Users/jsapran/AppData/Local/Programs/Microsoft%20VS%20Code/93cfdd489c/resources/app/out/vs/code/electron-browser/workbench/workbench.html) bean. The failure occurs in [org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit](vscode-file://vscode-app/c:/Users/jsapran/AppData/Local/Programs/Microsoft%20VS%20Code/93cfdd489c/resources/app/out/vs/code/electron-browser/workbench/workbench.html) because a datasource property lookup returns null.
   
   Env:
   Java 21
   Spring Boot 4.0.7
   ShardingSphere 5.5.3
   
   
   
   
   	@Primary
   	@Bean(name = "dataSource")
   	public DataSource dataSource() throws SQLException {
   
   		Map<String, DataSource> dataSourceMap = new HashMap<>();
   
   		dataSourceMap.put("master", createDataSource(dbHost));
   		dataSourceMap.put("slave1", createDataSource(dbHostSlave));
   
   		// =================================================
   		// READ WRITE SPLITTING
   		// =================================================
   
   		ReadwriteSplittingDataSourceGroupRuleConfiguration rwConfig = new ReadwriteSplittingDataSourceGroupRuleConfiguration(
   				"readwrite_ds", "master", List.of("slave1"), "round_robin");
   
   		ReadwriteSplittingRuleConfiguration readwriteRuleConfig = new ReadwriteSplittingRuleConfiguration(
   				List.of(rwConfig), Map.of("round_robin", new AlgorithmConfiguration("ROUND_ROBIN", new Properties())));
   
   		// =================================================
   		// SHARDING RULES
   		// =================================================
   
   		ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
   
   		//sharding tables rules
   
   		// =================================================
   		// SHARDING ALGORITHMS
   		// =================================================
   
   		//added in line algorithm configuration for readwrite splitting load balancer 
   
   		// =================================================
   		// SHARDINGSPHERE PROPERTIES
   		// =================================================
   
   		Properties props = new Properties();
   
   		props.setProperty("sql-show", shardingSpherePropsSqlShow);
   
   		// VERY IMPORTANT
   		props.setProperty("check-table-metadata-enabled", "false");
   		SingleRuleConfiguration singleRuleConfig = new SingleRuleConfiguration();
   
   		singleRuleConfig.getTables().add("*.*");
   		singleRuleConfig.getTables().add("*.*");
   		return ShardingSphereDataSourceFactory.createDataSource(dataSourceMap,
   				List.of(shardingRuleConfig, singleRuleConfig, readwriteRuleConfig), props);
   	}
   	
   	// =====================================================
   	// CREATE PHYSICAL DATASOURCE
   	// =====================================================
   	private DataSource createDataSource(String host) {
   
   		HikariDataSource ds = new HikariDataSource();
   
   		ds.setDriverClassName("com.mysql.cj.jdbc.Driver");
   
   		String jdbcUrl = "jdbc:mysql://" + host + ":" + dbPort + "/" + dbName + "?allowPublicKeyRetrieval=true"
   				+ "&useSSL=false" + "&serverTimezone=UTC";
   
   		ds.setJdbcUrl(jdbcUrl);
   		// ShardingSphere may expect a DataSource property named `url` (not only `jdbcUrl`).
   		// Ensure both are available so StorageUnit metadata extraction succeeds.
   		ds.addDataSourceProperty("url", jdbcUrl);
   
   		ds.setUsername(dbUsername);
   		ds.setPassword(dbPassword);
   
   		ds.setMaximumPoolSize(20);
   		ds.setMinimumIdle(5);
   
   		return ds;
   	}
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] ShardingSphereDataSourceFactory fails at runtime with NPE in StorageUnit during Spring Boot startup [shardingsphere]

Posted by "terrymanu (via GitHub)" <gi...@apache.org>.
terrymanu closed issue #38870: ShardingSphereDataSourceFactory fails at runtime with NPE in StorageUnit during Spring Boot startup
URL: https://github.com/apache/shardingsphere/issues/38870


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] ShardingSphereDataSourceFactory fails at runtime with NPE in StorageUnit during Spring Boot startup [shardingsphere]

Posted by "terrymanu (via GitHub)" <gi...@apache.org>.
terrymanu commented on issue #38870:
URL: https://github.com/apache/shardingsphere/issues/38870#issuecomment-4742556445

   Hi @Nilesh18398, thanks for reporting this.
   
   We need more information before treating this as a confirmed ShardingSphere bug. From the current evidence, the most likely cause is that the Hikari data-source-pool adapter is not available at runtime, so ShardingSphere cannot normalize Hikari's `jdbcUrl` into the standard `url` property expected by `StorageUnit`.
   
   Please first verify that `org.apache.shardingsphere:shardingsphere-infra-data-source-pool-hikari:5.5.3` is on the runtime classpath. If it is already present, please provide the full stack trace and the Maven/Gradle dependency tree for the failing application. I suggest labeling this as `status: need more info` and `in: JDBC` for now. If the Hikari adapter is present and the same NPE is still reproducible, we can reclassify it as a JDBC / infra data-source-pool bug.
   
   The reply above is based on the analysis below; the detailed reasoning is kept here for reference and follow-up contributors.
   
   ### Problem Understanding
   
   - **Issue:** A Spring Boot 4.0.7 / ShardingSphere 5.5.3 application creates a `ShardingSphereDataSource` through Java API with provided `HikariDataSource` instances and fails during startup with an NPE in `StorageUnit`.
   - **Topology:** JDBC + Standalone/N/A inferred from `ShardingSphereDataSourceFactory.createDataSource(dataSourceMap, configs, props)`; no governance mode or registry center is shown.
   - **Observed Evidence:** `OBS-1`, `OBS-2`, `OBS-3`, `OBS-4`, `OBS-5`, `OBS-6`
   
   ### Root Cause
   
   - **Observation:** `OBS-1` The issue body shows ShardingSphere 5.5.3, Hikari data sources configured with `setJdbcUrl(...)`, and no full stack trace or dependency tree: https://github.com/apache/shardingsphere/issues/38870
   - **Observation:** `OBS-2` The 5.5.3 Java API data source document uses `HikariDataSource#setJdbcUrl(...)` in the sample: https://shardingsphere.apache.org/document/5.5.3/en/user-manual/shardingsphere-jdbc/java-api/data-source/
   - **Observation:** `OBS-3` The 5.5.3 optional-plugin document says optional SPI implementations must be added when required, and lists `org.apache.shardingsphere:shardingsphere-infra-data-source-pool-hikari` as the Hikari connection-pool creation and property-adaptation implementation: https://shardingsphere.apache.org/document/5.5.3/en/user-manual/shardingsphere-jdbc/optional-plugins/
   - **Observation:** `OBS-4` The Hikari adapter maps standard `url` to Hikari `jdbcUrl`: `infra/data-source-pool/type/hikari/src/main/java/org/apache/shardingsphere/infra/datasource/pool/hikari/metadata/HikariDataSourcePoolMetaData.java:62`.
   - **Observation:** `OBS-5` `StorageUnit` expects `dataSourcePoolProps.getConnectionPropertySynonyms().getStandardProperties()` to contain `url` and calls `standardProps.get("url").toString()`: `infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnit.java:51`.
   - **Observation:** `OBS-6` `shardingsphere-jdbc` has the Hikari adapter only as a test dependency in this module, while the JDBC distribution includes it as a runtime dependency: `jdbc/pom.xml:105`, `distribution/jdbc/pom.xml:37`.
   - **Inference:** If the Hikari adapter jar is missing from the application runtime classpath, Hikari `jdbcUrl` will not be adapted to the standard `url` key, which can lead to the reported `StorageUnit` NPE. This inference depends on `OBS-3`, `OBS-4`, `OBS-5`, and `OBS-6`.
   - **Confidence:** Medium, because the issue does not include the full stack trace or dependency tree.
   
   ### Problem Analysis
   
   - **Issue Type:** Needs More Info
   - **Evidence:** The shown Java API usage is generally supported when Hikari property adaptation is available (`OBS-2`, `OBS-3`, `OBS-4`), but the actual runtime classpath is unknown (`OBS-1`).
   - **Duplicate Check:** Related issue #32183 has the same `StorageUnit` NPE shape for a custom connection pool, but it is not a direct duplicate because #38870 uses HikariCP, which has an official adapter when the optional plugin is present.
   - **Label Recommendation:** `status: need more info`, `in: JDBC`
   
   ### Problem Conclusion
   
   - **Evidence Confidence:** Medium
   - **Impact Scope:** ShardingSphere-JDBC Java API startup with provided Hikari data sources and data-source-pool property adaptation.
   - **Topology:** JDBC + Standalone/N/A inferred; exact mode not fully provided.
   - **Issue Type:** Needs More Info
   - **Recommended Labels:** `status: need more info`, `in: JDBC`
   - **Next Action:** Ask the reporter to verify the runtime dependency `org.apache.shardingsphere:shardingsphere-infra-data-source-pool-hikari:5.5.3`, then provide the full stack trace and dependency tree if the failure still reproduces.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] ShardingSphereDataSourceFactory fails at runtime with NPE in StorageUnit during Spring Boot startup [shardingsphere]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on issue #38870:
URL: https://github.com/apache/shardingsphere/issues/38870#issuecomment-4805048421

   There hasn't been any activity on this issue recently, and in order to prioritize active issues, it will be marked as stale.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org