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

Random StringIndexOutOfBoundsException when calling TitleAreaDialog.getMessage #2165

Closed
henryju opened this issue Mar 1, 2022 · 0 comments
Closed
Labels
Milestone

Comments

@henryju
Copy link

henryju commented Mar 1, 2022

Hi,

I have a test failing from time to time with this exception:

java.lang.StringIndexOutOfBoundsException: String index out of range: -1
	at java.base/java.lang.String.substring(String.java:1841)
	at org.eclipse.reddeer.jface.dialogs.TitleAreaDialog.getMessage(TitleAreaDialog.java:96)

I don't know how to reproduce.

We are waiting for an error message to be displayed in our Wizard:

// test code
 wizard.next();
 new WaitUntil(new DialogMessageIsExpected(wizard, "Authentication failed"));

// utility class
public class DialogMessageIsExpected extends AbstractWaitCondition {

  private final TitleAreaDialog dialog;
  private final String expectedMessage;

  public DialogMessageIsExpected(TitleAreaDialog dialog, String expectedMessage) {
    this.dialog = dialog;
    this.expectedMessage = expectedMessage;
  }

  @Override
  public boolean test() {
    return dialog.getMessage().equals(expectedMessage);
  }

}

The recording of the test shows that the message is present (but possibly the exception already occurred):
image

I guess it could be a race condition in TitleAreaDialog.getMessage:

public String getMessage() {
		checkShell();
		// Page Message is 5th Text within first Composite of TitleAreaDialog and is inactive 
		Control textControl = handler.getChildren(getShellComposite())[4];
		String message = "";
// -> At this moment the message and image are still empty
		if (textControl instanceof org.eclipse.swt.widgets.Label) {
			message = getMessageLabel(textControl).getText(); // message = ""
		} else {
			message = getMessageText(textControl).getText();
		}
// --> Here the message and image are changed to Error icon + "Authentication failed", but the message variable has already been assigned
		if(getMessageImage() != null){ // image is not null
			message = message.substring(1); // StringIndexOutOfBoundsException
		}
		return message;
	}

If I'm correct, a fix could be to add a guard before calling message.substring(1):

		if(getMessageImage() != null && message.length > 0){ //if image is shown TitleAreaDialog adds whitespace before message
			message = message.substring(1);
		}

Except if you can think of an atomic way of getting both the image and the message at the same time?

odockal added a commit to odockal/reddeer that referenced this issue Mar 2, 2022
Signed-off-by: Ondrej Dockal <odockal@redhat.com>
@odockal odockal closed this as completed in be8604b Mar 2, 2022
@odockal odockal added this to the 4.1.0 milestone Mar 24, 2022
@odockal odockal added the bug label Apr 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants