Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.config.AbstractFactoryBean;
Expand Down Expand Up @@ -72,17 +74,26 @@ public Class<? extends Resource[]> getObjectType() {
protected Resource[] createInstance() throws Exception {
List<Resource> scripts = new ArrayList<>();
for (String location : this.locations) {
List<Resource> resources = new ArrayList<>(
Arrays.asList(this.resourcePatternResolver.getResources(location)));
resources.sort((r1, r2) -> {
Resource[] resources = this.resourcePatternResolver.getResources(location);

// Cache URLs to avoid repeated I/O during sorting
Map<Resource, String> urlCache = new LinkedHashMap<>(resources.length);
for (Resource resource : resources) {
try {
return r1.getURL().toString().compareTo(r2.getURL().toString());
urlCache.put(resource, resource.getURL().toString());
}
catch (IOException ex) {
return 0;
throw new IllegalStateException(
Copy link

@famod famod Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change maintains the same output behavior while improving performance and error handling.

Are you guys sure about the "maintains the same output behavior" bit?

We're getting the following in Spring Boot 3.5.8 and lbruun/Pre-Liquibase:

Caused by: java.lang.IllegalStateException: Error when creating Resource object from "classpath:preliquibase/postgresql.sql"
        at net.lbruun.springboot.preliquibase.PreLiquibase.doGetResources(PreLiquibase.java:288)
        at net.lbruun.springboot.preliquibase.PreLiquibase.getResourcesFromStringLocations(PreLiquibase.java:266)
        at net.lbruun.springboot.preliquibase.PreLiquibase.getScripts(PreLiquibase.java:255)
        at net.lbruun.springboot.preliquibase.PreLiquibase.execute(PreLiquibase.java:127)
        at net.lbruun.springboot.preliquibase.PreLiquibaseAutoConfiguration.preLiquibase(PreLiquibaseAutoConfiguration.java:100)
        at java.base/java.lang.reflect.Method.invoke(Method.java:569)
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.lambda$instantiate$0(SimpleInstantiationStrategy.java:172)
        ... 104 more
Caused by: java.lang.IllegalStateException: Failed to resolve URL for resource [class path resource [preliquibase/postgresql.sql]] from location pattern [classpath:preliquibase/postgresql.sql]
        at org.springframework.jdbc.config.SortedResourcesFactoryBean.createInstance(SortedResourcesFactoryBean.java:86)
        at org.springframework.jdbc.config.SortedResourcesFactoryBean.createInstance(SortedResourcesFactoryBean.java:44)
        at org.springframework.beans.factory.config.AbstractFactoryBean.afterPropertiesSet(AbstractFactoryBean.java:142)
        at net.lbruun.springboot.preliquibase.PreLiquibase.doGetResources(PreLiquibase.java:285)
        ... 110 more
Caused by: java.io.FileNotFoundException: class path resource [preliquibase/postgresql.sql] cannot be resolved to URL because it does not exist
        at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:230)
        at org.springframework.jdbc.config.SortedResourcesFactoryBean.createInstance(SortedResourcesFactoryBean.java:83)
        ... 113 more

See https://github.com/lbruun-net/Pre-Liquibase/blob/1.6.1/autoconfigure/src/main/java/net/lbruun/springboot/preliquibase/PreLiquibase.java#L286

There is no such issue in SB 3.5.7.

FYI @lbruun

Edit/disclaimer: We're using src/main/resources/preliquibase/default.sql, but no postgresql.sql.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@famod,

Please note that this PR is already closed.

If you would like to report a regression against Spring Framework 6.2.13, please open a new GitHub issue.

Thanks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went ahead and created #35895 as a regression, to be fixed in 7.0.2 and 6.2.15.

"Failed to resolve URL for resource [" + resource +
"] from location pattern [" + location + "]", ex);
}
});
scripts.addAll(resources);
}

// Sort using cached URLs
List<Resource> sortedResources = new ArrayList<>(urlCache.keySet());
sortedResources.sort(Comparator.comparing(urlCache::get));

scripts.addAll(sortedResources);
}
return scripts.toArray(new Resource[0]);
}
Expand Down