Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When H2SchemaMetaDataLoader load column meta data, it will cause NullPointerException #24276

Closed
XinShepherd opened this issue Feb 21, 2023 · 8 comments

Comments

@XinShepherd
Copy link

XinShepherd commented Feb 21, 2023

Bug Report

Which version of ShardingSphere did you use?

5.2.1

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

ShardingSphere-JDBC

H2 version

      <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>1.4.200</version>
      </dependency>

Expected behavior

H2 Dialect load table meta data successfully

Actual behavior

Dialect load table meta data error.

the exception is:

2023-02-21 15:25:38.864  INFO 9167 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2023-02-21 15:25:38.867  INFO 9167 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2023-02-21 15:27:14.538 ERROR 9167 --- [           main] a.s.i.m.d.s.l.SchemaMetaDataLoaderEngine : Dialect load table meta data error.

java.sql.SQLException: Unknown exception: java.lang.NullPointerException
	at org.apache.shardingsphere.infra.util.exception.external.sql.ShardingSphereSQLException.toSQLException(ShardingSphereSQLException.java:54) ~[shardingsphere-infra-util-5.2.1.jar:5.2.1]
	at org.apache.shardingsphere.infra.metadata.database.schema.loader.SchemaMetaDataLoaderEngine.loadByDialect(SchemaMetaDataLoaderEngine.java:99) ~[shardingsphere-infra-common-5.2.1.jar:5.2.1]
	at org.apache.shardingsphere.infra.metadata.database.schema.loader.SchemaMetaDataLoaderEngine.load(SchemaMetaDataLoaderEngine.java:65) ~[shardingsphere-infra-common-5.2.1.jar:5.2.1]
	at org.apache.shardingsphere.infra.metadata.database.schema.builder.GenericSchemaBuilder.loadSchemas(GenericSchemaBuilder.java:95) [shardingsphere-infra-common-5.2.1.jar:5.2.1]
	at org.apache.shardingsphere.infra.metadata.database.schema.builder.GenericSchemaBuilder.build(GenericSchemaBuilder.java:78) [shardingsphere-infra-common-5.2.1.jar:5.2.1]
	at org.apache.shardingsphere.infra.metadata.database.schema.builder.GenericSchemaBuilder.build(GenericSchemaBuilder.java:66) [shardingsphere-infra-common-5.2.1.jar:5.2.1]
	at org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase.create(ShardingSphereDatabase.java:89) [shardingsphere-infra-common-5.2.1.jar:5.2.1]
	at org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabasesFactory.createGenericDatabases(ShardingSphereDatabasesFactory.java:81) [shardingsphere-infra-common-5.2.1.jar:5.2.1]
	at org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabasesFactory.create(ShardingSphereDatabasesFactory.java:69) [shardingsphere-infra-common-5.2.1.jar:5.2.1]
	at org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory.create(MetaDataContextsFactory.java:91) [shardingsphere-mode-core-5.2.1.jar:5.2.1]
	at org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory.create(MetaDataContextsFactory.java:69) [shardingsphere-mode-core-5.2.1.jar:5.2.1]
	at org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder.build(StandaloneContextManagerBuilder.java:49) [shardingsphere-standalone-mode-core-5.2.1.jar:5.2.1]
	at org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource.createContextManager(ShardingSphereDataSource.java:76) [shardingsphere-jdbc-core-5.2.1.jar:5.2.1]
	at org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource.<init>(ShardingSphereDataSource.java:64) [shardingsphere-jdbc-core-5.2.1.jar:5.2.1]
	at org.apache.shardingsphere.driver.api.ShardingSphereDataSourceFactory.createDataSource(ShardingSphereDataSourceFactory.java:93) [shardingsphere-jdbc-core-5.2.1.jar:5.2.1]

Reason analyze (If you can)

I have used the original datasource (not shardingDatasource) to init my tables in H2, and then H2SchemaMetaDataLoader will load the meta data from the datasource.

And then I debug the source code H2SchemaMetaDataLoader.java at line 112 which is the root cause , just like below
image
From the screenshot,we can find that the dataTypeMap does not contains the dataType '4', because the dataTypeMap is the TYPE_NAME to DATA_TYPE mappings, just like below
image

Solution

In my option, if we can directly use the value of dataType, and not get from dataTypeMap ?

@strongduanmu
Copy link
Member

Hi @XinShepherd, thank you for your feedback. Can you try to fix this bug?

@linghengqian
Copy link
Member

From the screenshot,we can find that the dataTypeMap does not contains the dataType '4', because the dataTypeMap is the TYPE_NAME to DATA_TYPE mappings, just like below

@strongduanmu
Copy link
Member

@linghengqian Thank you very much for your sharing, which means that the H2 2.x version has corrected the design errors in 1.x, and ShardingSphere currently supports it according to 2.x.

@XinShepherd
Copy link
Author

XinShepherd commented Feb 22, 2023

From the screenshot,we can find that the dataTypeMap does not contains the dataType '4', because the dataTypeMap is the TYPE_NAME to DATA_TYPE mappings, just like below

Thanks @linghengqian . So do you mean that I need to upgrade my H2 version from V1 to V2 ? Now shardingsphere-jdbc can work with this error, but I don't know if it will cause other errors.

@linghengqian
Copy link
Member

@XinShepherd

  • From a maintainability point of view, I feel that a downstream project should not stay at H2Database V1, because according to discussions on the H2Database maillist, V1 will not continue to release new versions.

  • You can still make a PR, because I don't know why this method is designed like this in the first place.

@XinShepherd
Copy link
Author

XinShepherd commented Feb 22, 2023

  • From a maintainability point of view, I feel that a downstream project should not stay at H2Database V1, because according to discussions on the H2Database maillist, V1 will not continue to release new versions.
  • You can still make a PR, because I don't know why this method is designed like this in the first place.

Thanks a lot @linghengqian . I upgrade my H2 version now and it works. And also, I will make a PR in the future if necessary.

@github-actions github-actions bot added the stale label Jul 12, 2023
@linghengqian
Copy link
Member

  • I'm just updating the current issue to avoid future misunderstandings. org.apache.shardingsphere.infra.metadata.database.schema.loader.dialect.H2SchemaMetaDataLoader has been refactored into org.apache.shardingsphere.infra.database.h2.metadata.data.loader.H2MetaDataLoader. There is still no related PR, and there is almost no way to test H2database V1 Server through H2database V2 Client.

@linghengqian
Copy link
Member

Considering the excessive number of CVEs for h2database 1.x, the current issue seems meaningless.

@linghengqian linghengqian closed this as not planned Won't fix, can't repro, duplicate, stale Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants