Uploaded image for project: 'Infinispan'
  1. Infinispan
  2. ISPN-8935

AbstractFileLookup.lookupFileStrict does not work for jar scheme

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 9.2.1.Final
    • 9.1.6.Final, 9.2.0.Final
    • Configuration, JCache
    • None

      As documented here, JAR URL has following syntax jar:<url>!/{entry}. Current implementation of AbstractFileLookup.lookupFileStrict does not rely on this syntax, and fails when correctly specified JAR URI comes in.

      I'm using Infinispan JCache implementation from Spring Boot. This works when run from gradle/maven/ide since in these cases file scheme is used. However, I'm targeting running Spring Boot app inside of Docker container where natural way for using Spring Boot apps is to deploy them as boot packaged fat jar. In that case, Spring Boot passes correct JAR URI into AbstractFileLookup.lookupFileStrict, which unfortunately fails silently and JCache reverts to default configuration.

      I believe that AbstractFileLookup.lookupFileStrict can be fixed by replacing current jar scheme handling

          case "jar":
             String uriAsString = uri.toString();
             String fileName = uriAsString.substring(uriAsString.lastIndexOf(":") + 1);
             return new FileInputStream(new File(fileName));
      

      with something like this

          case "jar": {
             // Invalid code commented out.
             //        String uriAsString = uri.toString();
             //        String fileName = uriAsString.substring(uriAsString.lastIndexOf(":") + 1);
             //        return new FileInputStream(new File(fileName));
             // ===== fix - start =====
             String uriAsString = uri.toString();
             String insideJarFilePath = uriAsString.substring(uriAsString.lastIndexOf("!") + 1);
      
             InputStream streamToBeReturned = getAsInputStreamFromClassLoader(insideJarFilePath, cl);
             if (streamToBeReturned == null) {
                throw log.unableToLoadFileUsingScheme(scheme);
             }
             return streamToBeReturned;
             // ===== fix - end =====
          }
      

      I'm using Infinispan 9.1.6, but I think that 9.2.0 has same problem. I will try to submit pull request.

              ttarrant@redhat.com Tristan Tarrant
              dmurat_jira Damir Murat (Inactive)
              Votes:
              2 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: