Skip to content

PathMatchingResourcePatternResolver inconsistently throws IOException in case of non-existing resources [SPR-7365] #12023

@spring-projects-issues

Description

@spring-projects-issues

Christian Cwienk opened SPR-7365 and commented

PathMatchingResourcePatternResolver behaves inconsistently (and imho in an unintuitive manner) as to the respect of throwing IOExceptions when resolving a given ant-style path pattern to concrete resources (tested with local filesystem):

In cases where no files are found (existing directory with no matching files), an empty array of Resource is returned (which is intuitive). If however, a part of the pathPattern does not exist (i.e. a directory does not exist), an IOException is being thrown unless the non-existing directory is specified after the first occurence of a wildcard, in which case an empty result array is returned.

imho, this is unintuitive and inconsistent for two reasons:

  1. I'd expect a path pattern matcher to try match applying a best-effort strategy; in case nothing can be matched, I'd regard that as a normal outcome and would expect to get an empty result-array (which in some but not all cases actually happens)

  2. Provided throwing an IOException in case part of the specified path does not exist made sense; then I'd expect this behaviour to be also applied for path parts after occurrences of wildcards (which is not the case).


I've created a possible solution for this issue by subclassing the class in question (see attached files). However I'd very much appreciate it if this change could be incorporated into a future release of the Spring framework.

Best Regards,

Christian


Affects: 2.5.6

Attachments:

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions