+1 to Mark's idea of throwing a runtime exception instead of returning null. 

Sent from my iPhone

On Jan 25, 2012, at 1:18, Gerhard Petracek <[email protected]> wrote:

> hi jason,
> 
> i just checked the original source-code in myfaces codi and there 'null' is
> part of the contract of the method.
> however, you are right - here it doesn't make sense since we are using it
> differently.
> 
> regards,
> gerhard
> 
> 
> 
> 2012/1/25 Jason Porter <[email protected]>
> 
>> As soon as I commit you'll see in rev 976dcbc the question I have, but for
>> the sake of getting the conversation going I'll paste the method here:
>> 
>> private Properties loadProperties(URL url)
>>   {
>>       Properties props = new Properties();
>> 
>>       InputStream inputStream = null;
>>       try
>>       {
>>           inputStream = url.openStream();
>> 
>>           if (inputStream != null)
>>           {
>>               props.load(inputStream);
>>           }
>>       }
>>       catch (IOException e)
>>       {
>>           return null; // TODO: Shouldn't this return an empty
>> Properties? Otherwise we could cause NPE in the getPropertyValue method
>>       }
>>       finally
>>       {
>>           try
>>           {
>>               if (inputStream != null)
>>               {
>>                   inputStream.close();
>>               }
>>           }
>>           catch (IOException e)
>>           {
>>               // no worries, means that the file is already closed
>>           }
>>       }
>> 
>>       return props;
>>   }
>> 
>> --
>> Jason Porter
>> http://lightguard-jp.blogspot.com
>> http://twitter.com/lightguardjp
>> 
>> Software Engineer
>> Open Source Advocate
>> Author of Seam Catch - Next Generation Java Exception Handling
>> 
>> PGP key id: 926CCFF5
>> PGP key available at: keyserver.net, pgp.mit.edu
>> 

Reply via email to