开发者

Weird RecordStore behavior when RecordStoreFullException occurs

开发者 https://www.devze.com 2022-12-23 17:38 出处:网络
I\'m developing a small J2ME application that displays bus stops timetables - they are stored as records in MIDP RecordStores.

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消