You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by "Karl Pauls (Jira)" <ji...@apache.org> on 2020/09/10 07:57:00 UTC

[jira] [Reopened] (FELIX-6326) Cannot read bundled resources with hash in the filename

     [ https://issues.apache.org/jira/browse/FELIX-6326?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Karl Pauls reopened FELIX-6326:
-------------------------------

Upon reflection, I think it is not a good idea to encode and decode the resource urls. 

While technically, that would be the correct solution (and solves this problem) I think this might cause more problems than it is fixing given that it worked unencoded in Felix like since forever. 

Specifically, I worry that there might be code that assumes it can construct URLs "by hand" and doesn't take encoding into account on the one hand. While on the other hand, there might be code that assumes it can take the path from a URL and do something meaningful with it without decoding. 

I'll think the better option is to just take the substring of the url at face value when looking up the resource. That still might break code that assumed that query or ref would be ignored but I think that would be a lot less likely than the alternative.

> Cannot read bundled resources with hash in the filename
> -------------------------------------------------------
>
>                 Key: FELIX-6326
>                 URL: https://issues.apache.org/jira/browse/FELIX-6326
>             Project: Felix
>          Issue Type: Bug
>          Components: Framework
>    Affects Versions: framework-6.0.3
>            Reporter: Oskar
>            Assignee: Karl Pauls
>            Priority: Major
>             Fix For: framework-6.0.4
>
>
> 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.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)