Total number of e-mail addresses conflicts the set maximum in Series 40 (Known Issue)
Article Metadata
Tested with
Compatibility
Series 40 5th Edition + FP1
Series 40 6th Edition
Article
Contents |
Overview
Contact.countValues(Contact.EMAIL) returns more e-mail values than the set maximum for the EMAIL field in Series 40.
Description
Starting from Series 40 3rd Edition, Feature Pack 1, the Series 40 implementation of the File Connection and PIM API (JSR-75) conforms to the Mobile Service Architecture Specification (JSR-248) which mandates that the ContactList field EMAIL must support at least 2 e-mail address values per contact. To conform to this requirement in Series 40, 2 e-mail addresses per contact is set as the maximum; if the field includes more than 2 e-mail addresses, IndexOutOfBoundsException will be thrown for the extra values when enumerating them.
Using PIMList.maxValues(Contact.EMAIL) it is possible to check the maximum number of data values that EMAIL field supports in the contact list, which in Series 40 is 2 as described above. In addition, Contact.countValues(Contact.EMAIL) returns the number of data values set in the EMAIL field: in the defined Series 40 Editions this total can exceed the maximum value returned by PIMList.maxValues(Contact.EMAIL). This can be considered illogical behaviour since the values which exceed the defined maximum will not be returned but IndexOutOfBoundsException will be thrown.
How to reproduce
- Browse for the native Phonebook application (Menu > Contacts) using a Series 40 device.
- Insert a new contact to the native Phonebook application.
- Insert e-mail for the new contact (Options > Add detail > E-mail address >) and insert an e-mail address into the text field. Repeat this step by adding at least two more e-mail addresses.
- Implement the test MIDlet by using the following code:
import java.util.Enumeration;
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
import javax.microedition.pim.*;
public class EmailAddressTest extends MIDlet implements CommandListener {
private Form form;
private Display display;
private Command exitCommand;
private Command searchCommand;
public EmailAddressTest() {
form = new Form("Email Address Test");
searchCommand = new Command("Search", Command.OK, 0);
exitCommand = new Command("Exit", Command.EXIT, 1);
form.addCommand(searchCommand);
form.addCommand(exitCommand);
form.setCommandListener(this);
display = Display.getDisplay(this);
display.setCurrent(form);
}
public void commandAction(Command cmd, Displayable displayable) {
if (cmd == exitCommand) {
notifyDestroyed();
} else if (cmd == searchCommand) {
try {
searchContact();
} catch (PIMException ex) {
ex.printStackTrace();
}
}
}
/* Search the added contact, return the maximum number of data
values that EMAIL field supports on the list, count the total
number of data values set in the EMAIL field. */
private void searchContact() throws PIMException {
PIM pim = PIM.getInstance();
PIMList list = pim.openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY);
Enumeration en = list.items();
Contact contact;
int countMax=0;
int count=0;
while (en.hasMoreElements()) {
contact = (Contact) en.nextElement();
countMax = list.maxValues(Contact.EMAIL);
count = contact.countValues(Contact.EMAIL);
for (int index = 0; index < count; index++) {
/* Append "all email values" to Form (including those which
exceed the defined maximum, i.e. all
'IndexOutOfBoundsException' values starting from index 2). */
form.append(""+index+":");
try {
String value = contact.getString(Contact.EMAIL, index);
if(value==null){
value="null";
}
form.append(""+value+"\n");
display.setCurrent(form);
} catch (IndexOutOfBoundsException e) {
form.append("ERROR: "+e.toString());
}
}
}
/* Append the defined maximum and total of all email values to Form. */
form.append("MaxValues: "+countMax+"\n");
form.append("CountValues: "+count+"\n");
}
public void startApp() {}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
}
5. Install and launch the test MIDlet and press 'Search'. The MIDlet returns first two e-mail addresses as entered by the user and throws 'ERROR: java.lang.IndexOutofBoundsException' for all the following e-mail addresses.
In addition, the maximum number of data values that EMAIL field supports on the list (2 for Series 40) will be returned together with the total number of data values set in the EMAIL field (which includes all e-mail addresses as entered by the user).
Solution
No solution exists.


(no comments yet)