Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webadmin: avoid NPE on null rx, tx drops #832

Merged
merged 1 commit into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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