Skip to content

Commit

Permalink
webadmin: avoid NPE on null rx, tx drops
Browse files Browse the repository at this point in the history
Bug-Url: http://bugzilla.redhat.com/2180230
Change-Id: Iee6fa946f52481091a431a6ef0f173d74f9e37f2
Signed-off-by: Eitan Raviv <eraviv@redhat.com>
  • Loading branch information
erav committed Apr 18, 2023
1 parent f78c60f commit c80df40
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.ovirt.engine.ui.common.widget.renderer;

import java.math.BigInteger;

import com.google.gwt.text.shared.AbstractRenderer;

/**
* Renderer for Rx/Tx drop rates.
*/
public class RxTxDropRenderer extends AbstractRenderer<BigInteger[]> {

private static final String ZERO_VALUE = "0"; //$NON-NLS-1$

@Override
public String render(BigInteger[] values) {
if (values.length != 2 || values[0] == null && values[1] == null) {
return ZERO_VALUE;
} else if (values[0] == null) {
return String.valueOf(values[1]);
} else if (values[1] == null) {
return String.valueOf(values[0]);
} else {
return String.valueOf(values[0].add(values[1]));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.ovirt.engine.ui.webadmin.widget.host;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -165,7 +166,7 @@ public String getValue(HostInterface hostInterface) {
TextColumn<HostInterface> dropRate = new TextColumn<HostInterface>() {
@Override
public String getValue(HostInterface hostInterface) {
return String.valueOf(hostInterface.getRxDrop().add(hostInterface.getTxDrop()));
return dropRenderer.render(new BigInteger[]{hostInterface.getRxDrop(), hostInterface.getTxDrop()});
}
};
slavesTable.addColumn(dropRate, templates.sub(constants.dropsInterface(), constants.pkts()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.ovirt.engine.ui.common.css.PatternflyConstants;
import org.ovirt.engine.ui.common.widget.listgroup.ExpandableListViewItem;
import org.ovirt.engine.ui.common.widget.listgroup.PatternflyListViewItem;
import org.ovirt.engine.ui.common.widget.renderer.RxTxDropRenderer;
import org.ovirt.engine.ui.common.widget.renderer.RxTxRateRenderer;
import org.ovirt.engine.ui.common.widget.renderer.RxTxTotalRenderer;
import org.ovirt.engine.ui.common.widget.table.column.AbstractIconTypeColumn;
Expand Down Expand Up @@ -57,6 +58,7 @@ public class HostNetworkInterfaceListViewItem extends PatternflyListViewItem<Hos

protected static final RxTxRateRenderer rateRenderer = new RxTxRateRenderer();
protected static final RxTxTotalRenderer totalRenderer = new RxTxTotalRenderer();
protected static final RxTxDropRenderer dropRenderer = new RxTxDropRenderer();
private static final int MAX_LOGICAL_NETWORKS = 1000;
private static final String ICON_COLOR = "#363636"; // $NON-NLS-1$
private static final String EXPANSION_CONTAINER = "expansion-container"; // $NON-NLS-1$
Expand Down

0 comments on commit c80df40

Please sign in to comment.