Embedded database opened with jdbc:hsqldb:res: does not work at all when HSQLDB is on the module-path instead of the class-path. To reproduce, take any embedded database which works well with HSQL on the classpath. Just put HSQL on the module-path instead and try again. HSQL said that the database does not exist.
HSQL performs 3 steps for opening embedded databases:
1) org.hsqldb.DatabaseURL adds the / prefix to the database path. For example, "jdbc:hsql:res:my-path/my-database" become "/my-path/my-database". The leading slash is problematic and should not be added for the reason explained below.
2) org.hsqldb.lib.FileAccessRes opens the resources with getClass().getResource("/my-path/my-database.something"). Normally, Class.getResource searches for resources in a directory relative to the class, which is an HSQL class rather than a class related to the user's database. The leading / in the database path is for ignoring the class directory and search from the root instead. However, in the context of Java Modules, the use of Class.getResource is restricted. Not only the search of resources is relative to the directory of the class, but in addition the access authorizations are determined by the class. HSQL does not have access to resources of modules that HSQL does not read (requires directive in module-info). Therefore, while this approach returns a non-null value when HSQL is on the class-path, it returns null when HSQL is on the module-path. This approach does not work in context of Java modules and should be removed. It is fundamentally wrong because getClass().getResource in this context should be for loading a HSQL resource, not an user resource. If HSQL really wants to use Class.getResource, then the class needs to be a user's class, not a HSQL class.
3) org.hsqldb.lib.FileAccessRes fallbacks on Thread.currentThread().getContextClassLoader().getResource("/my-path/my-database.something"). This approach would work… if it wasn't for the / prefix added in step 1. A resource opened with ClassLoader.getResource is always relative to the root, and the / prefix is illegal. This fallback probably never worked, even with HSQL on the class-path, because of malformed resource path.
I propose to remove steps 1 and 2, keep only step 3 but with a valid path (without the / prefix). I verified that with these changes, embedded HSQL database works on the module path. A patch is attached to this issue.
Does this change still allow opening the res database when on class path, rather than module path?