SQLFileChange broken relative path resolving

After upgrading from 4.15.0 to 4.21.1 we found exception, when execute our scripts.

We are often using relative pathes to our changes. So it works correctly until we updates to last release.

We have changeset into another changeset with relative path to parent

<changeSet author="nufefelov" id="Create_tables" runOrder="first">
        <comment>Создание таблиц</comment>
        <sqlFile relativeToChangelogFile="true"
                 path="../../oracle/crtable.sql"
                 encoding="Cp1251"
                 dbms="oracle"/>
        <sqlFile relativeToChangelogFile="true"
                 path="../../postgresql/crtable.sql"
                 encoding="UTF-8"
                 dbms="postgresql"/>
    </changeSet>

Since update we got error
liquibase.exception.LiquibaseException: liquibase.exception.UnexpectedLiquibaseException: java.io.FileNotFoundException: JAR entry com/asuproject/usoi/db/manage/scripts/liquibase/scheme/../../oracle/crtable.sql not found in D:\usoi5\master\core\build\libs\exploded\core.war\WEB-INF\lib\com.asuproject-usoi-db-scripts-5.x.jar

I found, that there are changes in SQLFileChange.java

There is method, that calculates relative path correctly (4.15.0)

@Override
    public InputStream openSqlStream() throws IOException {
        if (path == null) {
            return null;
        }

        InputStream inputStream;
        try {
            String relativeTo = null;
            if (ObjectUtil.defaultIfNull(isRelativeToChangelogFile(), false)) {
                relativeTo = getChangeSet().getChangeLog().getPhysicalFilePath();
            }
            inputStream = Scope.getCurrentScope().getResourceAccessor().openStream(relativeTo, path);
        } catch (IOException e) {
            throw new IOException("Unable to read file '" + path + "'", e);
        }

        if (inputStream != null) {
            return inputStream;
        }
        throw new IOException(FileUtil.getFileNotFoundMessage(path));
    }

And there is new version of this code, that does’not work from 4.21.1

@Override
    public InputStream openSqlStream() throws IOException {
        if (path == null) {
            return null;
        }

        ResourceAccessor resourceAccessor = Scope.getCurrentScope().getResourceAccessor();
        if (ObjectUtil.defaultIfNull(isRelativeToChangelogFile(), false)) {
            return resourceAccessor.get(getChangeSet().getChangeLog().getPhysicalFilePath()).resolveSibling(path).openInputStream();
        } else {
            return resourceAccessor.getExisting(path).openInputStream();
        }
    }

The method resolveSiblings() does’nt resolve it.

Hi @Bostandyksoft,

You are probably correct. This looks like a legitimate issue. Would you mind creating a Github issue for this? Issues · liquibase/liquibase · GitHub

-PJ

Hi. I’ve copied topic to github issue

1 Like