[izpack-devel] Patch for suppressing null pointer in RuleInputField

Dennis Reil Dennis.Reil at reddot.de
Wed Aug 30 10:27:19 CEST 2006


Hi,

When I use a rule input field in UserInputPanel, I always get a null
pointer exception from caretUpdate() in RuleInputField. This is caused
by an activeField set to null somewhere else. So just test if
activeField equals null before calling any method on it.

Below you'll find a patch for this problem.

kind regards,
     Dennis




Index: /workspace/IzPack3-trunk/src/lib/com/izforge/izpack/panels/RuleInputField.java
===================================================================
--- /workspace/IzPack3-trunk/src/lib/com/izforge/izpack/panels/RuleInputField.java	(revision 1554)
+++ /workspace/IzPack3-trunk/src/lib/com/izforge/izpack/panels/RuleInputField.java	(working copy)

@@ -748,17 +748,20 @@
     /*--------------------------------------------------------------------------*/
     public void caretUpdate(CaretEvent event)
     {
-        String text = activeField.getText();
-        int fieldSize = activeField.getEditLength();
-        int caretPosition = activeField.getCaretPosition();
-        int selection = activeField.getSelectionEnd() -
activeField.getSelectionStart();
-
-        if ((!inputFields.lastElement().equals(activeField)) && (!
activeField.unlimitedEdit()))
+        if (activeField != null)
         {
-            if ((text.length() == fieldSize) && (selection == 0) &&
(caretPosition == fieldSize)
-                    && !backstep)
+            String text = activeField.getText();
+            int fieldSize = activeField.getEditLength();
+            int caretPosition = activeField.getCaretPosition();
+            int selection = activeField.getSelectionEnd() -
activeField.getSelectionStart();
+
+            if ((!inputFields.lastElement().equals(activeField)) && (!
activeField.unlimitedEdit()))
             {
-                activeField.transferFocus();
+                if ((text.length() == fieldSize) && (selection == 0)
+                        && (caretPosition == fieldSize) && !backstep)
+                {
+                    activeField.transferFocus();
+                }
             }
         }
     }






More information about the izpack-devel mailing list