Project

General

Profile

Bug #5073

NPE in ComboBoxGuiImpl

Added by Vladimir Tsichevski over 3 years ago. Updated over 3 years ago.

Status:
Review
Priority:
Normal
Target version:
-
Start date:
Due date:
% Done:

80%

billable:
No
vendor_id:
GCD
case_num:

History

#1 Updated by Vladimir Tsichevski over 3 years ago

The following code:

DEF VAR cb AS CHAR VIEW-AS COMBO-BOX SIMPLE LIST-ITEMS 
   "item1", "item2", "item3", "item4", "item5" size 10 by 3.

DEFINE FRAME fr cb
   WITH CENTERED SIZE 80 BY 20 SIDE-LABELS.

ENABLE ALL WITH FRAME fr.
WAIT-FOR GO OF FRAME fr.

causes NPE here:

Caused by: java.lang.NullPointerException
        at com.goldencode.p2j.ui.client.format.StringFormat.<init>(StringFormat.java:180)
        at com.goldencode.p2j.ui.client.format.DisplayFormatFactory.makeFormat(DisplayFormatFactory.java:124)
        at com.goldencode.p2j.ui.ControlConfig.setDynamicFormat(ControlConfig.java:355)
        at com.goldencode.p2j.ui.client.gui.ComboBoxGuiImpl.createEntryField(ComboBoxGuiImpl.java:1556)
        at com.goldencode.p2j.ui.client.gui.ComboBoxGuiImpl.setVisible(ComboBoxGuiImpl.java:830)
        at com.goldencode.p2j.ui.client.Frame.enableAllWidgets(Frame.java:7967)
        at com.goldencode.p2j.ui.chui.ThinClient.processEnable(ThinClient.java:5795)

Here no format spec is defined for the combo-box, so null is passed where it is not expected:

   private void createEntryField()
   {
      ...
      // format must be ignored if not explicitly defined, compute from item values
      String fmt = config.format != null && !config.format.isEmpty() ? config.format : null;  
      finCfg.setDynamicFormat(fmt);

#2 Updated by Vladimir Tsichevski over 3 years ago

The fix can probably look like:

      // format must be ignored if not explicitly defined, compute from item values
      final String fmt = config.format;
      if (fmt != null && !fmt.isEmpty())
      {
         finCfg.setDynamicFormat(fmt);
      }

#3 Updated by Vladimir Tsichevski over 3 years ago

  • % Done changed from 0 to 60

#4 Updated by Greg Shah over 3 years ago

I have no objection.

Constantin: You're in this area right now, what do you think?

#5 Updated by Constantin Asofiei over 3 years ago

Vladimir, I agree the NPE needs to be fixed and your solution seems OK. But I can't make 4GL be aware of this format. I've tried this:

DEF VAR cb AS CHAR format "x(2)" VIEW-AS COMBO-BOX SIMPLE LIST-ITEMS 
   "item1", "item2", "item3", "item4", "item5" size 10 by 3.

def var ch as char format "x(2)".
DEFINE FRAME fr cb ch
   WITH CENTERED SIZE 80 BY 20 SIDE-LABELS.

ENABLE ALL WITH FRAME fr.

cb:format = "x(8)".
message cb:format ch:format.

WAIT-FOR GO OF FRAME fr.

No matter where I set the combo's format (explicitly via the FORMAT option or its attribute), this doesn't seem to be have any effect on the number of entered characters.

Looks like for the combo with SIMPLE mode the FORMAT affects only the initial value, when the widget is uninitialized.

Does FWD allow more then the number of chars in the format to be entered? Because OE doesn't seem to have a limit.

#6 Updated by Vladimir Tsichevski over 3 years ago

Constantin Asofiei wrote:

Vladimir, I agree the NPE needs to be fixed and your solution seems OK. But I can't make 4GL be aware of this format. I've tried this:
[...]

No matter where I set the combo's format (explicitly via the FORMAT option or its attribute), this doesn't seem to be have any effect on the number of entered characters.

Moreover, starting from the 62-th character inserted, it starts to trim the last 38 character entered.

Looks like for the combo with SIMPLE mode the FORMAT affects only the initial value, when the widget is uninitialized.

From my observations, it ignores the initial value completely, and set all characters to spaces, the number of spaces according to the format.

It is obviously a bug, so we should not copy it to FWD. Instead, we have to decide, which would be a proper behaviour in FWD.

#7 Updated by Constantin Asofiei over 3 years ago

If you use an UPDATE instead of ENABLE/WAIT-FOR, you will see that the initial value is being used.

#8 Updated by Vladimir Tsichevski over 3 years ago

Constantin Asofiei wrote:

If you use an UPDATE instead of ENABLE/WAIT-FOR, you will see that the initial value is being used.

You are right. I added the update cb. statement, now the initial value is visible.

#9 Updated by Vladimir Tsichevski over 3 years ago

  • Status changed from New to WIP

#10 Updated by Vladimir Tsichevski over 3 years ago

  • % Done changed from 60 to 80
  • Status changed from WIP to Review

The original issue resolved in branch 3821c revision 11918.
The sidelong issues probably need further discussion.

Also available in: Atom PDF