Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-11676

UrlResource.exists() does not properly detect JBoss vfszip resources

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Complete
    • Affects Version/s: 3.2.8, 4.0.3
    • Fix Version/s: 3.2.9, 4.0.4, 4.1 RC1
    • Component/s: Core
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              juergen.hoeller Juergen Hoeller
              Reporter:
              podlesh Kamil Podlešák
              Last updater:
              Spring Issues Spring Issues
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Days since last comment:
                3 years, 31 weeks, 2 days ago