Skip to content

FILE_READ from JAR filesystem on classpath results in file of length 0 #3730

@prodj17

Description

@prodj17

Reading a resource from a JAR file on the classpath results in a 0 length read.
As as simple test, with a maven project using a H2 in-memory database, if you execute:
SELECT LENGTH(FILE_READ('classpath:/org/h2/store/fs/FileUtils.class')) LEN
The result is 0.

The fix for issue #446 unfortunately doesn't work if the resource URL resolves to something like

jar:file:/.../.m2/repository/com/h2database/h2/2.1.210/h2-2.1.210.jar!/org/h2/store/fs/FileUtils.class

size() in FilePathDisk.java line 68 tries to apply Paths.get to the resolved URL.
This fails with a java.nio.file.FileSystemNotFoundException and then returns 0, which results in 0 bytes being read from the resource.

This is a reopen of #3395 and this is not the same thing as #1702 which 3395 was marked as a duplicate of.

This happens when trying to load a classpath resource that is in a jar, due to the fact that the java Zip filesystem for that specific JAR is not initialized.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions