Allon Mureinik has uploaded a new change for review. Change subject: userportal: fix possible NPE in % progress bar ......................................................................
userportal: fix possible NPE in % progress bar DoublePercentageProgressBar unboxes valueA and valueB (into fakeA and fakeB, respectively), and only then checks if they were null. If either of them is indeed null, we will get a NullPointerException from the outboxing, and won't even reach the null check. This patch moves the relevant code into the null-safe condition. Change-Id: Id7a65802cc79a698863899085189ea80fcc6d57f Signed-off-by: Allon Mureinik <amure...@redhat.com> --- M frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/widget/DoublePercentageProgressBar.java 1 file changed, 13 insertions(+), 11 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/34/12334/1 diff --git a/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/widget/DoublePercentageProgressBar.java b/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/widget/DoublePercentageProgressBar.java index 50c6c0e..d4006de 100644 --- a/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/widget/DoublePercentageProgressBar.java +++ b/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/widget/DoublePercentageProgressBar.java @@ -1,11 +1,11 @@ package org.ovirt.engine.ui.userportal.widget; -import com.google.gwt.resources.client.CssResource; import org.ovirt.engine.ui.common.idhandler.HasElementId; import com.google.gwt.core.client.GWT; import com.google.gwt.editor.client.IsEditor; import com.google.gwt.editor.client.adapters.TakesValueEditor; +import com.google.gwt.resources.client.CssResource; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.user.client.TakesValue; @@ -75,19 +75,21 @@ } public void setBars() { - int fakeA = valueA; - int fakeB = valueB; + if (valueA != null && valueB != null) { + int fakeA = valueA; + int fakeB = valueB; + if (valueA + valueB >= FULL_WIDTH) { + double factor = (double) (FULL_WIDTH - 1) / (valueA + valueB); + fakeA = (int) Math.round(factor * valueA); + fakeB = (int) Math.round(factor * valueB); - if (valueA != null && valueB != null && valueA + valueB >= FULL_WIDTH) { - double factor = (double)(FULL_WIDTH-1) / (valueA + valueB); - fakeA = (int)Math.round(factor * valueA); - fakeB = (int)Math.round(factor * valueB); + fakeA = (fakeB == 0 ? FULL_WIDTH : fakeA); + fakeB = (fakeA == 0 ? FULL_WIDTH : fakeB); + } - fakeA = (fakeB == 0 ? FULL_WIDTH : fakeA); - fakeB = (fakeA == 0 ? FULL_WIDTH : fakeB); + setBar(percentageBarA, percentageLabelA, valueA, fakeA, style.percentageLabelBlack()); + setBar(percentageBarB, percentageLabelB, valueB, fakeB, style.percentageLabel()); } - setBar(percentageBarA, percentageLabelA, valueA, fakeA, style.percentageLabelBlack()); - setBar(percentageBarB, percentageLabelB, valueB, fakeB, style.percentageLabel()); } private void setBar(FlowPanel percentageBar, Label percentageLabel, Integer value, int fakeValue, String style){ -- To view, visit http://gerrit.ovirt.org/12334 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id7a65802cc79a698863899085189ea80fcc6d57f Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Allon Mureinik <amure...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches