Posts for the month of September 2006

A Regress Bug in java.awt.geom.Path2D (JDK 6.0 beta 2)

I tested AIOTrade on newly downloaded JDK 6.0 beta 2, and got an exception instantly:

java.lang.ArrayIndexOutOfBoundsException: 0
    at java.awt.geom.Path2D$Float.moveTo(Path2D.java:322)
    at java.awt.geom.Path2D$Float.append(Path2D.java:643)
    at java.awt.geom.Path2D.append(Path2D.java:1780)

The code run good in JDK 5.0, so will it be a regress bug in JDK 6.0?

I then checked the source code: 6.0 vs 5.0, and found there were likely a bit of code omited wrongly. That is, in method body of void needRoom(boolean needMove, int newCoords), should add

                if (grow < 1) {
                    grow = 1;
                }
at the next of:
            int size = pointTypes.length;
            if (numTypes >= size) {
                int grow = size;
                if (grow > EXPAND_MAX) {
                    grow = EXPAND_MAX;
                }

The following is the proper code I've tested OK:

        void needRoom(boolean needMove, int newCoords) {
            if (needMove && numTypes == 0) {
                throw new IllegalPathStateException("missing initial moveto "+
                        "in path definition");
            }
            int size = pointTypes.length;
            if (numTypes >= size) {
                int grow = size;
                if (grow > EXPAND_MAX) {
                    grow = EXPAND_MAX;
                }
                /** fix bug:
                 * java.lang.ArrayIndexOutOfBoundsException: 0
                 *     at java.awt.geom.Path2D$Float.moveTo(Path2D.java:322)
                 *     at java.awt.geom.Path2D$Float.append(Path2D.java:643)
                 *     at java.awt.geom.Path2D.append(Path2D.java:1780)
                 */
                if (grow < 1) {
                    grow = 1;
                }
                pointTypes = Arrays.copyOf(pointTypes, size+grow);
            }
            size = floatCoords.length;
            if (numCoords + newCoords > size) {
                int grow = size;
                if (grow > EXPAND_MAX * 2) {
                    grow = EXPAND_MAX * 2;
                }
                if (grow < newCoords) {
                    grow = newCoords;
                }
                floatCoords = Arrays.copyOf(floatCoords, size+grow);
            }
        }

As I can not wait for it be fixed in JDK, so I wrote another org.aiotrade.util.awt.geom.Path2D and org.aiotrade.util.awt.geom.GeneralPath, and replaced the java.awt.geom.GeneralPath in my source tree. you can get the code at:

GeneralPath.java
Path2D.java

It Will Be My First Attendance at NetBeans Day, Seattle

I will be there, Sun Tech Days, Seattle, Sep 6, 2006. As I'm now in Vancouver, it's about 2 or 3 hours trip to Seattle.

I'm glad to have a chance to meet those great guys who develop NetBeans IDE and Platform. As you know, the AIOTrade (formerly Humai Trader) is built on NetBeans Platform using NetBeans IDE.

And, I've committed the re-packed source code to SVN repository on sourceforge.net, and am doing cleanup on the neural network code, hope to commit the code in one week.

For the neural network module, there should be a lot of UI works still needed to be done, I've been beginning to hack the Visual Library API of NetBeans, and hope to apply these great works on visual neural network definition.