Committed by
Mao Jianwei - BUPT
Improve the method to loading configurations from OSGI
To avoid null value error, Use Tools.get() in org.onlab.util.Tools to load configs safely. Refer to https://wiki.onosproject.org/display/ONOS/Component+Configuration Change-Id: Ic8ab5bd41d1e374a0abb3c78e94c28df7854b85d
Showing
1 changed file
with
5 additions
and
6 deletions
... | @@ -35,6 +35,7 @@ import org.onlab.packet.TCP; | ... | @@ -35,6 +35,7 @@ import org.onlab.packet.TCP; |
35 | import org.onlab.packet.TpPort; | 35 | import org.onlab.packet.TpPort; |
36 | import org.onlab.packet.UDP; | 36 | import org.onlab.packet.UDP; |
37 | import org.onlab.packet.VlanId; | 37 | import org.onlab.packet.VlanId; |
38 | +import org.onlab.util.Tools; | ||
38 | import org.onosproject.cfg.ComponentConfigService; | 39 | import org.onosproject.cfg.ComponentConfigService; |
39 | import org.onosproject.core.ApplicationId; | 40 | import org.onosproject.core.ApplicationId; |
40 | import org.onosproject.core.CoreService; | 41 | import org.onosproject.core.CoreService; |
... | @@ -372,8 +373,8 @@ public class ReactiveForwarding { | ... | @@ -372,8 +373,8 @@ public class ReactiveForwarding { |
372 | String propertyName) { | 373 | String propertyName) { |
373 | Integer value = null; | 374 | Integer value = null; |
374 | try { | 375 | try { |
375 | - String s = (String) properties.get(propertyName); | 376 | + String s = Tools.get(properties, propertyName); |
376 | - value = isNullOrEmpty(s) ? value : Integer.parseInt(s.trim()); | 377 | + value = isNullOrEmpty(s) ? value : Integer.parseInt(s); |
377 | } catch (NumberFormatException | ClassCastException e) { | 378 | } catch (NumberFormatException | ClassCastException e) { |
378 | value = null; | 379 | value = null; |
379 | } | 380 | } |
... | @@ -391,10 +392,8 @@ public class ReactiveForwarding { | ... | @@ -391,10 +392,8 @@ public class ReactiveForwarding { |
391 | String propertyName) { | 392 | String propertyName) { |
392 | boolean enabled = false; | 393 | boolean enabled = false; |
393 | try { | 394 | try { |
394 | - String flag = (String) properties.get(propertyName); | 395 | + String flag = Tools.get(properties, propertyName); |
395 | - if (flag != null) { | 396 | + enabled = isNullOrEmpty(flag) ? enabled : flag.equals("true"); |
396 | - enabled = flag.trim().equals("true"); | ||
397 | - } | ||
398 | } catch (ClassCastException e) { | 397 | } catch (ClassCastException e) { |
399 | // No propertyName defined. | 398 | // No propertyName defined. |
400 | enabled = false; | 399 | enabled = false; | ... | ... |
-
Please register or login to post a comment