Project: SWT
Bug 239220 Text.getText() returns empty string after calling setText() with non-empty string
Reported: 2008-07-02 07:30:29 | Status: resolved fixed

Here is the (new as of June 23rd) code for Text on Carbon: public String getText () { checkWidget(); if (txnObject == 0) { return new String (getEditText (0, -1)); } else { return getTXNText (OS.kTXNStartOffset, OS.kTXNEndOffset); } } char [] getEditText (int start, int end) { int [] ptr = new int [1]; int [] actualSize = new int [1]; int result = OS.GetControlData (handle, (short)OS.kControlEntireControl, OS.kControlEditTextCFStringTag, 4, ptr, actualSize); if (result != OS.noErr) return new char [0]; int length = OS.CFStringGetLength (ptr [0]); end = Math.min (end, length - 1); if (start > end) return new char [0]; // method continues ... If txnObject == 0, getText() calls getEditText(0, -1) which returns an empty result if start > end. But start is 0 and end is -1, hence 0 > -1 is true, which cannot be right. This has caused the Mac-specific data binding test failures over the last couple of days, and also may have caused the other UI test failures on the Mac.

Files changed in fix:
bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Text.java tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Text.java