Skip to content

UrlResource.exists() does not properly detect JBoss vfszip resources [SPR-11676] #16299

@spring-projects-issues

Description

@spring-projects-issues

Kamil Podlešák opened SPR-11676 and commented

Method org.springframework.core.io.AbstractFileResolvingResource#exists treats jboss vfs URLs (protocol starting with "vfs") as files: it calls getFile().exists(). There is no fallback.

Unfortunately, vfszip:// resources (files inside JAR files) do not support getFile() and throw exception (see org.springframework.core.io.VfsUtils#getFile the "is nested" if command).

One obvious fix would be to provide fallback (that is, if getFile() throws an exception, it continues by handling the URL).
At this moment, the only solution is to not use exists(), but this workaround code instead:

Resource res = ldr.getResource(locator);
boolean exists = false;
try {
    //!!HACK!!
    // Jboss vfzip:// does not support  exists() method
    // so we'll just try opening it and handle exception
    res.getInputStream().close();
    exists = true;
} catch (IOException e) {
    log.info(this, "cannot open meta.xml", e);
}
if (!exists) {

Apparently, this is probably also root cause of SEC-1700


Affects: 3.2.8, 4.0.3

Issue Links:

Backported to: 3.2.9

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions