Just An Application

December 11, 2009

What’s New In MIDP 3.0: Redux – Events

Filed under: Java, JME, MIDP, MIDP3, MIDP3EventAPI — Tags: , , , , — Simon Lewis @ 3:27 pm

Original Post

Changes Since Proposed Final Draft

New EventPermission Action

The class javax.microedition.event.EventPermission now supports
the

    postsystem

action.

An EventPermission with the postsystem action is required to post any event, using the EventManager.post(EventData, boolean) method, if it is a system event.

A system event is any event whose name is contained in the result returned by a call to the EventManager.getSystemEvents() method.

This makes it much easier to prevent unidentified third-party MIDlets from posting fake SYSTEM_STATE events for example.

Issues

EventData.getDouble()

If the EventData value is a String then this method is defined to return the result of calling the method

    java.lang.Double.parseDouble(String)

Both CLDC and CDC define this method in terms of the

    java.lang.Double.valueOf(String)

method.

The format supported by the CLDC version of the method is defined as


    FloatValue:

        Signopt FloatingPointLiteral

The format supported by the CDC version of the method is defined as


    FloatValue:

        Signopt NaN
        Signopt Infinity
        Signopt FloatingPointLiteral

In each case the definition of FloatingPointLiteral is that in the JLS.

Hence the EventData.getDouble() method will behave differently when running on CLDC and CDC if the value is the String Infinity or NaN.

This is a minor point but it would have been very easy to fix.

EventData.getFloat()

Analagously to the getDouble() method, this method is defined in terms of the

    java.lang.Float.parseFloat(String)

method.

The CLDC version of this method does not explicitly specify what format(s) it supports. The CDC version is defined in terms of the method

    java.lang.Float.valueOf(String)

which supports the same format as the Double version.

Depending on the format supported by the CLDC implementation the EventData.getFloat() method may or may not suffer from the same problem as EventData.getDouble().

Again, this is a minor point but it would have been very easy to fix.

In addition the documentation contradicts itself. The table clearly shows that if the value of the Event is boolean then the value 1.0 is returned if it is true, and the value 0.0 if it is false, yet the documentation states that a NumberFormatException is thrown

If the value is a boolean or can not be parsed as a float value.

At a minimum this should have been picked up during the writing of the TCK since somebody should have been writing a test for this case.

EventData.getLong()

Being very pedantic, but this is supposed to be an official specification, the documentation states that it returns

The value as an int.

which it does not.

The MIDlet-Event-Launch-<n> Attribute

Double Values

For the case where the Event value is a double, the value of this attribute is defined as

    <Event-Name>=<Double-Event-Value>,<Double-Event-Value>

The value of a Double-Event-Value

must contain only characters valid for Floating Point Literals as defined by the Java Language Specification [JLS] and are accepted by the java.lang.Double.valueOf method.[sic]

As written this excludes negative decimal values . It is not clear whether this is intentional. It would have been better to provide an explicit definition of the format.

Again this is something that the people writing the TCK would have picked up on,

Long Values

For the case where the Event value is a long, the value of this attribute is defined as

    <Event-Name>=<Long-Event-Value>,<Long-Event-Value>

The value of a Long-Event-Value

must contain only characters valid for Long Literals as defined by the Java Language Specification [JLS] and are accepted by the java.lang.Long.valueOf method.

As written this excludes negative decimal values. In addition, the CLDC version of java.lang.Long does not have a valueOf method

How did the people writing the TCK know what to test ?


Copyright (c) 2009 By Simon Lewis. All Rights Reserved.

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: