You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Claude Warren <cl...@xenei.com> on 2016/11/21 09:11:13 UTC

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

(posted to user@commons.apache.org)  For background see:
https://issues.apache.org/jira/browse/CONFIGURATION-641?
page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&
focusedCommentId=15681474#comment-15681474

Perhaps there is a bigger problem with the semantics of the classes.  I
come late to this project having used version 1.x and not participated or
followed any of the development discussion for 2.x versions.  So from a
pseudo-noob point of view perhaps the Configuration objects should not have
a read/write method that does not take a FileHandler object.

I think this makes sense in that you can create a configuration and do a
lot with it without reading or writeing it.  The read/write issues arise
because of resolution issues in reading/writing (e.g. resolving include
statements).

Perhaps in version 2.2 the read/write methods could be deprecated in favor
of _read() and _write() (renaming the methods in FileBased) and FileHandler
could be renamed to IOHandler.  So reading from a stream, file, ByteBuffer,
etc would be handled by the IOHandler.  It seem counter inturitive that a
FileHandler would be needed to read/write a configuration to a Stream.

Just thoughts.  Any comments?

Claude

On Sun, Nov 20, 2016 at 5:07 PM, Oliver Heger (JIRA) <ji...@apache.org>
wrote:

>
>     [ 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)
>



-- 
I like: Like Like - The likeliest place on the web
<http://like-like.xenei.com>
LinkedIn: http://www.linkedin.com/in/claudewarren