You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Oliver Heger (JIRA)" <ji...@apache.org> on 2016/11/20 17:07:58 UTC

[jira] [Commented] (CONFIGURATION-641) XMLConfiguration.load may throw NPE

    [ https://issues.apache.org/jira/browse/CONFIGURATION-641?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15681474#comment-15681474 ] 

Oliver Heger commented on CONFIGURATION-641:
--------------------------------------------

Agreed that it is not a good style to throw a NPE here. However, the underlying problem here is that the read() method should not be called directly, but a {{FileHandler}} object should be used to load or save a configuration as described at
http://commons.apache.org/proper/commons-configuration/userguide/howto_filebased.html#File_Operations_on_Configurations

The documentation of read() and write() methods should be improved to state this.

> XMLConfiguration.load may throw NPE
> -----------------------------------
>
>                 Key: CONFIGURATION-641
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-641
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 2.1
>         Environment: Java 8 / Linux
>            Reporter: Claude Warren
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> I expect that 
> {noformat}
>     URL url = Test.class.getResource( "/Test.xml");	
>     XMLConfiguration config = new XMLConfiguration();
>     config.read( url.openStream());
> {noformat}
> Would read the XML file.  However it will throw a NPE at line 967
> {noformat}
>  private void load(InputSource source) throws ConfigurationException
>     {
>         try
>         {
>             URL sourceURL = locator.getSourceURL(); // <- NPE here
>             if (sourceURL != null)
>             {
>                 source.setSystemId(sourceURL.toString());
>             }
> {noformat}
> I believe that testing for locator == null first will solve the problem as the rest of the code in the method does not appear to use it.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)