Uploaded image for project: 'Felix'
  1. Felix
  2. FELIX-6326

Cannot read bundled resources with hash in the filename

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • framework-6.0.3
    • framework-6.0.4
    • Framework
    • None

    Description

      Trying to access a resource via class.getResourceAsStream() fails with NPE if the file name contains hash (#).

      Example bundle code to verify the fault:

      @Component(immediate = true)
      public class ResourceReader
      {
      private static final Logger LOG = LogManager.getLogger();

      @Activate
      public void activate()

      { String fileNameWithoutHashes = "file_without_hash.txt"; logFileContent(fileNameWithoutHashes);String fileNameWithHashes = "file#with#hash.txt"; logFileContent(fileNameWithHashes); }

      private void logFileContent(String resourceFileName)}}
      {
      InputStream stream = ResourceReader.class.getResourceAsStream("/" + resourceFileName);
      try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(stream)))

      { LOG.info(bufferedReader.readLine()); }

      catch (Exception e)

      { LOG.error("FAILURE: Could not read " + resourceFileName); }

      }
      }

      Resource files located in bundle root:
      /file_without_hash.txt - content irrelevant
      /file#with#hash.txt - content irrelevant

      Problem is seen in Karaf using Felix framework. Switching to Equinox made the problem disappear.

      Attachments

        Issue Links

          Activity

            People

              karlpauls Karl Pauls
              Bengtson Oskar
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: