views:

113

answers:

1

Hello everyone!

I'm developing a small J2ME application that displays bus stops timetables - they are stored as records in MIDP RecordStores.

Sometimes records can not fit a single RecordStore, especially on record update - using setRecord method - a RecordStoreFullException occurs. I catch the exception, and try to write the record to a new RecordStore along with deleting the previous one in the old RecordStore. Everything works fine except of deleting record from RecordStore where the RecordStoreFullException occurs. If I make an attempt to delete record that could not be updated, another Exception of type InvalidRecordIDException is thrown. This is weird and undocumented in MIDP javadoc. I have tested it on Sun WTK 2.5.2, MicroEdition SDK 3.0 and Nokia Series 40 SDK. Furthermore I created a code that reproduces this strange behaviour:


RecordStore rms = null;
        int id = 0;
        try {
            rms  = RecordStore.openRecordStore("Test", true);
            byte[] raw = new byte[192*10024]; //Big enough to cause RecordStoreFullException
            id = rms.addRecord(raw, 0, 160);
            rms.setRecord(id, raw, 0, raw.length);
        } catch (Exception e) {
            try {
                int count = rms.getNumRecords();
                RecordEnumeration en = rms.enumerateRecords(null, null, true);
                count = en.numRecords();
                while(en.hasNextElement()){
                    System.out.println("NextID: "+en.nextRecordId());
                }
                rms.deleteRecord(id); //this won't work!
                rms.setRecord(id, new byte[5], 0, 5); //this won't work too!
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }

I added extra enumeration code to produce other weird behavior - when RecordStoreFullException occurs, count variable will be set to 1 (if RMS was empty) by both methods - getNumRecords and numRecords. System.out.println will produce NextID: 0! It is not acceptable because record ID can not be 0! Could someone explain this strange behavior?

Sorry for my bad English.

A: 

Are you sure setRecord throws RecordStoreFullException?

If addRecord throws RecordStoreFullException then id is never updated and you are trying to deleteRecord(0), which could explain the InvalidRecordIDException.

The Enumeration code seems to me like it demonstrates a real bug in both Sun and Nokia's implementation of RMS (which could be the same things since Series40 used KVM for a long while). You may be able to pinpoint it (assuming it is still there) by looking at the source code of Sun's implementation at https://phoneme.dev.java.net/

I would advise trying the same on a Series60 phone as it would contain an implementation of RMS developed by Symbian.

QuickRecipesOnSymbianOS
Yes it does. But it depends on emulator/phone You use - on my real Nokia 6233 this behavior occurs - but You must experiment with rawData array length - sometimes it can be too small to cause an exception.
Michael P
addRecord can probably never throw an Exception because of small amount of bytes written.
Michael P
addRecord *could* be implemented badly enough to throw the exception. it's worth just getting the exception stack trace to make sure.
QuickRecipesOnSymbianOS
I'm sure it is not - the code snippet I provide is only an example - addRecord must be called in order to add at least one record to the store. The setRecord call causes an exception - I checked it, using step by step debugger mode.
Michael P
And yes - stack trace points to setRecord code line
Michael P
alright. looks like the RMS implementation doesn't fail correctly when it throws the exception. there's still not much you can do beyond checking the source of PhoneME and trying on Series60.
QuickRecipesOnSymbianOS