You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@karaf.apache.org by Glen Mazza <gm...@talend.com> on 2011/10/13 01:49:51 UTC

Hmm. (Re: svn commit: r1182554....)

Are "if" clauses without braces allowed?  I haven't seen those in a while.

Glen

On 10/12/2011 03:38 PM, jbonofre@apache.org wrote:
> Author: jbonofre
> Date: Wed Oct 12 19:38:14 2011
> New Revision: 1182554
>
> URL: http://svn.apache.org/viewvc?rev=1182554&view=rev
> Log:
> [KARAF-932] Initialize the config properties if null to avoid NPE
>
> Modified:
>      karaf/branches/karaf-2.2.x/management/mbeans/config/src/main/java/org/apache/karaf/management/mbeans/config/internal/ConfigMBeanImpl.java
>
> Modified: karaf/branches/karaf-2.2.x/management/mbeans/config/src/main/java/org/apache/karaf/management/mbeans/config/internal/ConfigMBeanImpl.java
> URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.2.x/management/mbeans/config/src/main/java/org/apache/karaf/management/mbeans/config/internal/ConfigMBeanImpl.java?rev=1182554&r1=1182553&r2=1182554&view=diff
> ==============================================================================
> --- karaf/branches/karaf-2.2.x/management/mbeans/config/src/main/java/org/apache/karaf/management/mbeans/config/internal/ConfigMBeanImpl.java (original)
> +++ karaf/branches/karaf-2.2.x/management/mbeans/config/src/main/java/org/apache/karaf/management/mbeans/config/internal/ConfigMBeanImpl.java Wed Oct 12 19:38:14 2011
> @@ -85,6 +85,8 @@ public class ConfigMBeanImpl extends Sta
>               throw new IllegalArgumentException("Configuration PID " + pid + " doesn't exist");
>           }
>           Dictionary dictionary = configuration.getProperties();
> +        if (dictionary == null)
> +            dictionary = new java.util.Properties();
>           Map<String, String>  propertiesMap = new HashMap<String, String>();
>           for (Enumeration e = dictionary.keys(); e.hasMoreElements(); ) {
>               Object key = e.nextElement();
> @@ -100,6 +102,8 @@ public class ConfigMBeanImpl extends Sta
>               throw new IllegalArgumentException("Configuration PID " + pid + " doesn't exist");
>           }
>           Dictionary dictionary = configuration.getProperties();
> +        if (dictionary == null)
> +            dictionary = new java.util.Properties();
>           dictionary.remove(key);
>           store(pid, dictionary, false);
>       }
> @@ -110,6 +114,8 @@ public class ConfigMBeanImpl extends Sta
>               throw new IllegalArgumentException("Configuration PID " + pid + " doesn't exist");
>           }
>           Dictionary dictionary = configuration.getProperties();
> +        if (dictionary == null)
> +            dictionary = new java.util.Properties();
>           Object currentValue = dictionary.get(key);
>           if (currentValue == null) {
>               dictionary.put(key, value);
> @@ -127,6 +133,8 @@ public class ConfigMBeanImpl extends Sta
>               throw new IllegalArgumentException("Configuration PID " + pid + " doesn't exist");
>           }
>           Dictionary dictionary = configuration.getProperties();
> +        if (dictionary == null)
> +            dictionary = new java.util.Properties();
>           dictionary.put(key, value);
>           store(pid, dictionary, false);
>       }
>
>


-- 
Glen Mazza
Talend - http://www.talend.com/apache
Blog - http://www.jroller.com/gmazza
Twitter - glenmazza


Re: Hmm. (Re: svn commit: r1182554....)

Posted by Andreas Pieber <an...@gmail.com>.
Haven't read the karaf coding standard but I'm very much in favor of using
braces here; it's simply to easy making a mistake otherwise...

Kind regards,
Andreas

On Thu, Oct 13, 2011 at 01:49, Glen Mazza <gm...@talend.com> wrote:

> Are "if" clauses without braces allowed?  I haven't seen those in a while.
>
> Glen
>
> On 10/12/2011 03:38 PM, jbonofre@apache.org wrote:
>
>> Author: jbonofre
>> Date: Wed Oct 12 19:38:14 2011
>> New Revision: 1182554
>>
>> URL: http://svn.apache.org/viewvc?**rev=1182554&view=rev<http://svn.apache.org/viewvc?rev=1182554&view=rev>
>> Log:
>> [KARAF-932] Initialize the config properties if null to avoid NPE
>>
>> Modified:
>>     karaf/branches/karaf-2.2.x/**management/mbeans/config/src/**
>> main/java/org/apache/karaf/**management/mbeans/config/**
>> internal/ConfigMBeanImpl.java
>>
>> Modified: karaf/branches/karaf-2.2.x/**management/mbeans/config/src/**
>> main/java/org/apache/karaf/**management/mbeans/config/**
>> internal/ConfigMBeanImpl.java
>> URL: http://svn.apache.org/viewvc/**karaf/branches/karaf-2.2.x/**
>> management/mbeans/config/src/**main/java/org/apache/karaf/**
>> management/mbeans/config/**internal/ConfigMBeanImpl.java?**
>> rev=1182554&r1=1182553&r2=**1182554&view=diff<http://svn.apache.org/viewvc/karaf/branches/karaf-2.2.x/management/mbeans/config/src/main/java/org/apache/karaf/management/mbeans/config/internal/ConfigMBeanImpl.java?rev=1182554&r1=1182553&r2=1182554&view=diff>
>> ==============================**==============================**
>> ==================
>> --- karaf/branches/karaf-2.2.x/**management/mbeans/config/src/**
>> main/java/org/apache/karaf/**management/mbeans/config/**internal/ConfigMBeanImpl.java
>> (original)
>> +++ karaf/branches/karaf-2.2.x/**management/mbeans/config/src/**
>> main/java/org/apache/karaf/**management/mbeans/config/**internal/ConfigMBeanImpl.java
>> Wed Oct 12 19:38:14 2011
>> @@ -85,6 +85,8 @@ public class ConfigMBeanImpl extends Sta
>>              throw new IllegalArgumentException("**Configuration PID " +
>> pid + " doesn't exist");
>>          }
>>          Dictionary dictionary = configuration.getProperties();
>> +        if (dictionary == null)
>> +            dictionary = new java.util.Properties();
>>          Map<String, String>  propertiesMap = new HashMap<String,
>> String>();
>>          for (Enumeration e = dictionary.keys(); e.hasMoreElements(); ) {
>>              Object key = e.nextElement();
>> @@ -100,6 +102,8 @@ public class ConfigMBeanImpl extends Sta
>>              throw new IllegalArgumentException("**Configuration PID " +
>> pid + " doesn't exist");
>>          }
>>          Dictionary dictionary = configuration.getProperties();
>> +        if (dictionary == null)
>> +            dictionary = new java.util.Properties();
>>          dictionary.remove(key);
>>          store(pid, dictionary, false);
>>      }
>> @@ -110,6 +114,8 @@ public class ConfigMBeanImpl extends Sta
>>              throw new IllegalArgumentException("**Configuration PID " +
>> pid + " doesn't exist");
>>          }
>>          Dictionary dictionary = configuration.getProperties();
>> +        if (dictionary == null)
>> +            dictionary = new java.util.Properties();
>>          Object currentValue = dictionary.get(key);
>>          if (currentValue == null) {
>>              dictionary.put(key, value);
>> @@ -127,6 +133,8 @@ public class ConfigMBeanImpl extends Sta
>>              throw new IllegalArgumentException("**Configuration PID " +
>> pid + " doesn't exist");
>>          }
>>          Dictionary dictionary = configuration.getProperties();
>> +        if (dictionary == null)
>> +            dictionary = new java.util.Properties();
>>          dictionary.put(key, value);
>>          store(pid, dictionary, false);
>>      }
>>
>>
>>
>
> --
> Glen Mazza
> Talend - http://www.talend.com/apache
> Blog - http://www.jroller.com/gmazza
> Twitter - glenmazza
>
>

Re: Hmm. (Re: svn commit: r1182554....)

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi Glen,

I will use braces as it's clearer.

Regards
JB

On 10/13/2011 01:49 AM, Glen Mazza wrote:
> Are "if" clauses without braces allowed? I haven't seen those in a while.
>
> Glen
>
> On 10/12/2011 03:38 PM, jbonofre@apache.org wrote:
>> Author: jbonofre
>> Date: Wed Oct 12 19:38:14 2011
>> New Revision: 1182554
>>
>> URL: http://svn.apache.org/viewvc?rev=1182554&view=rev
>> Log:
>> [KARAF-932] Initialize the config properties if null to avoid NPE
>>
>> Modified:
>> karaf/branches/karaf-2.2.x/management/mbeans/config/src/main/java/org/apache/karaf/management/mbeans/config/internal/ConfigMBeanImpl.java
>>
>>
>> Modified:
>> karaf/branches/karaf-2.2.x/management/mbeans/config/src/main/java/org/apache/karaf/management/mbeans/config/internal/ConfigMBeanImpl.java
>>
>> URL:
>> http://svn.apache.org/viewvc/karaf/branches/karaf-2.2.x/management/mbeans/config/src/main/java/org/apache/karaf/management/mbeans/config/internal/ConfigMBeanImpl.java?rev=1182554&r1=1182553&r2=1182554&view=diff
>>
>> ==============================================================================
>>
>> ---
>> karaf/branches/karaf-2.2.x/management/mbeans/config/src/main/java/org/apache/karaf/management/mbeans/config/internal/ConfigMBeanImpl.java
>> (original)
>> +++
>> karaf/branches/karaf-2.2.x/management/mbeans/config/src/main/java/org/apache/karaf/management/mbeans/config/internal/ConfigMBeanImpl.java
>> Wed Oct 12 19:38:14 2011
>> @@ -85,6 +85,8 @@ public class ConfigMBeanImpl extends Sta
>> throw new IllegalArgumentException("Configuration PID " + pid + "
>> doesn't exist");
>> }
>> Dictionary dictionary = configuration.getProperties();
>> + if (dictionary == null)
>> + dictionary = new java.util.Properties();
>> Map<String, String> propertiesMap = new HashMap<String, String>();
>> for (Enumeration e = dictionary.keys(); e.hasMoreElements(); ) {
>> Object key = e.nextElement();
>> @@ -100,6 +102,8 @@ public class ConfigMBeanImpl extends Sta
>> throw new IllegalArgumentException("Configuration PID " + pid + "
>> doesn't exist");
>> }
>> Dictionary dictionary = configuration.getProperties();
>> + if (dictionary == null)
>> + dictionary = new java.util.Properties();
>> dictionary.remove(key);
>> store(pid, dictionary, false);
>> }
>> @@ -110,6 +114,8 @@ public class ConfigMBeanImpl extends Sta
>> throw new IllegalArgumentException("Configuration PID " + pid + "
>> doesn't exist");
>> }
>> Dictionary dictionary = configuration.getProperties();
>> + if (dictionary == null)
>> + dictionary = new java.util.Properties();
>> Object currentValue = dictionary.get(key);
>> if (currentValue == null) {
>> dictionary.put(key, value);
>> @@ -127,6 +133,8 @@ public class ConfigMBeanImpl extends Sta
>> throw new IllegalArgumentException("Configuration PID " + pid + "
>> doesn't exist");
>> }
>> Dictionary dictionary = configuration.getProperties();
>> + if (dictionary == null)
>> + dictionary = new java.util.Properties();
>> dictionary.put(key, value);
>> store(pid, dictionary, false);
>> }
>>
>>
>
>

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com