Github user jburwell commented on a diff in the pull request:
https://github.com/apache/cloudstack/pull/735#discussion_r37865908
--- Diff:
plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java
---
@@ -286,7 +287,11 @@ private void deleteExitingLinkLocalRouteTable(String
linkLocalBr) {
String[] lines = parser.getLines().split("\\n");
for (String line : lines) {
String[] tokens = line.split(" ");
- if (!tokens[2].equalsIgnoreCase(linkLocalBr)) {
+ if (tokens != null && tokens.length < 2) {
+ continue;
+ }
+ final String device = tokens[2];
+ if (!Strings.isNullOrEmpty(device) &&
!device.equalsIgnoreCase(linkLocalBr)) {
--- End diff --
Reading through this block, it feels like lines 289-293 should be extracted
to a private method:
```
static parseDevice(final String line) {
final String[] tokens = line.split( " ");
if (tokens != null && tokens.length < 2) {
return "";
}
final String device = tokens[2];
return Strings.isNullOrEmpty(device) : " " ? device;
}
```
The extraction of this method would not only shorten the
deleteExitingLinkLocalLocalRoutetTable method, but clearly express the intent.
It also allows a unit test to be written to verify that parsing works as
expected for different types of input.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---