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

Oskar updated KARAF-6845:
-------------------------
    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 used:
 src/main/resources/file_without_hash.txt - content irrelevant
 src/main/resources/file#with#hash.txt - content irrelevant

 

_Running the test outside of Karaf do not give any issues._

  was:
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 used:
 src/main/resources/file_without_hash.txt - content irrelevant
 src/main/resources/file#with#hash.txt - content irrelevant

 

_Running the test outside of Karaf do not give any issues._


> Cannot read resource files with hash sign in the name
> -----------------------------------------------------
>
>                 Key: KARAF-6845
>                 URL: https://issues.apache.org/jira/browse/KARAF-6845
>             Project: Karaf
>          Issue Type: Bug
>          Components: karaf
>    Affects Versions: 4.1.4, 4.3.0, 4.2.7
>         Environment: Karaf 4.1.4, 4.2.7, 4.3.0.RC1 executed with both Java8 
> and Java11 on Ubuntu and Suse Linux
>            Reporter: Oskar
>            Priority: Major
>
> 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 used:
>  src/main/resources/file_without_hash.txt - content irrelevant
>  src/main/resources/file#with#hash.txt - content irrelevant
>  
> _Running the test outside of Karaf do not give any issues._



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

Reply via email to