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

AbstractFileLookup.lookupFileStrict broken on Windows

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 9.2.1.Final
    • 8.2.5.Final, 9.0.0.Alpha4, 9.0.0.Beta1
    • Core
    • None

    Description

      The fix in ISPN-5949 breaks Windows compatibility.

      infinispan.xml is configured in application.properties

      spring.cache.jcache.config=classpath:spring/infinispan.xml
      

      When using Infinispan in a Spring Boot application (fat jar or Eclipse IDE) the following exception is thrown:

      Caused by: org.infinispan.commons.CacheConfigurationException:
      com.ctc.wstx.exc.WstxIOException: Stream closed
      	at org.infinispan.configuration.parsing.ParserRegistry.parse(ParserRegistry.java:119)
      	at org.infinispan.jcache.embedded.JCacheManager.getConfigurationBuilderHolder(JCacheManager.java:100)
      	at org.infinispan.jcache.embedded.JCacheManager.<init>(JCacheManager.java:56)
      	at org.infinispan.jcache.embedded.JCachingProvider.createCacheManager(JCachingProvider.java:46)
      	at org.infinispan.jcache.AbstractJCachingProvider.getCacheManager(AbstractJCachingProvider.java:67)
      	at org.springframework.boot.autoconfigure.cache.JCacheCacheConfiguration.createCacheManager(JCacheCacheConfiguration.java:101)
              ...
      

      When AbstractFileLookup.lookupFileStrict() is called in JCacheManager.getConfigurationHolder() the URI used for infinispan.xml looks something like this:

      • fat jar
        jar:file:/C:/projects/myapp/myservice-0.0.1.jar!/spring/infinispan.xml
        
      • running app from within IDE
        file:/C:/projects/workspace/myservice/target/classes/spring/infinispan.xml
        

      The problem ist now twofold:

      1. First this nasty 'C:' in the Windows path breaks the parsing code in AbstractFileLookup.lookupFileStrict(), as lastIndexOf(':') cuts the drive letter from the path and not just 'jar:file:' as intended. The resulting fileName cannot be resolved and cl.getResourceAsStream(fileName) returns null.
           public InputStream lookupFileStrict(URI uri, ClassLoader cl) throws FileNotFoundException {
              //in case we don't have only file schema, but {{jar:file}} schema too, we have to get rid of all schemas
              int startIndex = uri.toString().lastIndexOf(':');
              String fileName = uri.toString().substring(startIndex + 1);
        
              return cl.getResourceAsStream(fileName);
           }
        
      2. This method gets called too when running from within an IDE (at least Eclipse with Maven integration). But in this case Spring JCacheCacheConfiguration magic (createCachemanager() - configLocation.getURI()) resolves this path to a full path as seen above (not a classpath relative to /target/classes). As this path ist not on the classpath, cl.getResourceAsStream(fileName) returns null.

      In both cases lookupFileStrict returns null as InputStream which in turn leads to the exception mentioned above.

      The old code of lookupFileStrict()

      return new FileInputStream(new File(uri));
      

      works fine from within the IDE, but is broken for a fat jar (ISPN-5949).

      I am currently trying to find a workaround for this. But as far as I can see, the current behaviour (fix or no fix) is going to a problem when developing/running Infinispan enabled applications on Windows.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              ridcully42 Valued Customer (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: