InputVerifier goos into infinite loop for no discernible reason
I have a JFormattedTextField with an input verifier specified in the constructor as
this.setInputVerifier(new SecNameInputVerifier());
Here's the implementation of the InputVerifier:
publicclass SecNameInputVerifierextends InputVerifier{
private IOPanel ioContainer = FrameReference.requestIoPanel();
publicboolean verify(JComponent input){
String title ="Create Section Dialog";
String message =
"A Section with that name already exists. \n" +
"Please choose another name.";
if (inputinstanceof JFormattedTextField){
try{
JFormattedTextField ftf = (JFormattedTextField)input;
//check if section is valid for its heirarchical location in the tree
System.err.println("verify() invoked");// Line 1
if (ioContainer.sysConfigPanel.sysActionListener.validateAddSection(
ftf.getText(),true)){// Line 2
//check if section already exists
if (!secExists(ftf.getText())){
returntrue;
}
else{
//section already exists
JOptionPane.showMessageDialog(ioContainer, message, title,
JOptionPane.ERROR_MESSAGE);
}
}
}//end try
catch(Exception e){
e.printStackTrace();
}
}
returnfalse;
}
publicboolean shouldYieldFocus(JComponent input){
return verify(input);
}
privateboolean secExists(String secName){
if (ioContainer.sysConfigPanel.treePanel.numInstances(secName) > 0){
returntrue;
}
else{
returnfalse;
}
}
}
The program fails in the verify() method when the JFormattedTextField object loses focus. I've indicated Line 1 and Line 2 in the comments, which I'll reference here. Line 2 invokes a method that checks for validity of the text that was entered. In the failure scenario, this method returns false. Stepping through with the debugger, after Line 2 returns, the program then executes Line 1. Then it executes Line 2 again, returns false, goes back to Line 1, in an infinite loop until a stack overflow occurs.
It seems strange to execute the line above when it returns, but I'm going to assume that my IDE debugger is muddling things up a bit. The method should return false, but the debugger doesn't show the "return false" statement being executed. Then I'm going to assume that the shouldYieldFocus() method gets called again for some reason, which calls the verify() method, and for some reason the debugger skips all that and shows Line 1 as the next statement to execute. This is the only explanation I can think of for what otherwise would look like retrograde execution.
But if this is the case, I have no idea why shouldYiedlFocus() keeps getting called. Anyone know what I'm missing? I don't have any listeners on the JFormattedTextField, and I have no idea why the input verifier is being called repeatedly instead of just once when it loses focus.
Something else that's strange is that within the method invoked by Line 2 (validateAddSection()), there is code to open a JOptionPane. I see this code execute with the debugger, but the JOptionPane never shows up.
I'm completely at a dead end. I hope someone can shed some light on this.

