发生 RecordStoreFullException 时奇怪的 RecordStore 行为

发布于 2024-08-25 14:07:19 字数 1584 浏览 3 评论 0原文

我正在开发一个小型 J2ME 应用程序,用于显示公交车站时间表 - 它们作为记录存储在 MIDP RecordStores 中。

有时记录无法容纳单个 RecordStore,尤其是在记录更新时 - 使用 setRecord 方法 - 会发生 RecordStoreFullException。我捕获了异常,并尝试将记录写入新的 RecordStore,同时删除旧 RecordStore 中的前一个记录。 除了从发生 RecordStoreFullException 的 RecordStore 中删除记录之外,一切正常。如果我尝试删除无法更新的记录,则会引发另一个 InvalidRecordIDException 类型的异常。这很奇怪并且在 MIDP javadoc 中没有记录。我已经在 Sun WTK 2.5.2、MicroEdition SDK 3.0 和 Nokia Series 40 SDK 上对其进行了测试。此外,我创建了一个代码来重现这种奇怪的行为:


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();
            }
        }

我添加了额外的枚举代码来产生其他奇怪的行为 - 当 RecordStoreFullException 发生时,计数变量将通过两种方法 - getNumRecords 和 numRecords 设置为 1(如果 RMS 为空)。 System.out.println 将产生 NextID: 0!这是不可接受的,因为记录 ID 不能为 0! 有人可以解释这种奇怪的行为吗?

抱歉我的英语不好。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海风掠过北极光 2024-09-01 14:07:19

您确定 setRecord 抛出 RecordStoreFullException 吗?

如果 addRecord 抛出 RecordStoreFullExceptionid 永远不会更新,并且您正在尝试 deleteRecord(0),这可以解释InvalidRecordIDException

在我看来,枚举代码似乎展示了 Sun 和 Nokia 的 RMS 实现中的真正错误(这可能是相同的事情,因为 Series40 使用 KVM 很长一段时间)。您可以通过查看 https 上 Sun 实现的源代码来查明它(假设它仍然存在) ://phoneme.dev.java.net/

我建议在 Series60 手机上尝试同样的操作,因为它包含 Symbian 开发的 RMS 实现。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文