pivot-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sandro Martini <sandro.mart...@gmail.com>
Subject checks
Date Tue, 10 Apr 2012 11:15:43 GMT
Hi all,
looking at the problem found by Jerome (on shortcuts, actions, and
menus) I  tried to run ActionMappingTest, but when closing it (after
opening some dialogs with shortcuts configured there), i get the
following exception:

java.lang.IndexOutOfBoundsException: index 0 out of bounds [0,-1].
	at org.apache.pivot.collections.ArrayList.verifyIndexBounds(ArrayList.java:580)
	at org.apache.pivot.collections.ArrayList.get(ArrayList.java:346)
	at org.apache.pivot.wtk.Container.get(Container.java:249)
	at org.apache.pivot.wtk.Window.isBottomMost(Window.java:1021)
	at org.apache.pivot.wtk.Window.clearActive(Window.java:961)
	at org.apache.pivot.wtk.Window.setParent(Window.java:485)
	at org.apache.pivot.wtk.Container.remove(Container.java:205)
	at org.apache.pivot.wtk.Container.remove(Container.java:179)
	at org.apache.pivot.wtk.Window.close(Window.java:736)
	at org.apache.pivot.tests.ActionMappingTest.shutdown(ActionMappingTest.java:62)
	at org.apache.pivot.wtk.DesktopApplicationContext.exit(DesktopApplicationContext.java:409)
	at org.apache.pivot.wtk.DesktopApplicationContext.exit(DesktopApplicationContext.java:394)
	at org.apache.pivot.wtk.DesktopApplicationContext$HostFrame.processWindowEvent(DesktopApplicationContext.java:236)
	at java.awt.Window.processEvent(Window.java:1822)
	at java.awt.Component.dispatchEventImpl(Component.java:4653)
	at java.awt.Container.dispatchEventImpl(Container.java:2097)
	at java.awt.Window.dispatchEventImpl(Window.java:2482)
	at java.awt.Component.dispatchEvent(Component.java:4481)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:648)
	at java.awt.EventQueue.access$000(EventQueue.java:84)
	at java.awt.EventQueue$1.run(EventQueue.java:607)
	at java.awt.EventQueue$1.run(EventQueue.java:605)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
	at java.awt.EventQueue$2.run(EventQueue.java:621)
	at java.awt.EventQueue$2.run(EventQueue.java:619)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:618)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)


So I think that there are some places where we should do better checks
... for example I suggest to add the following (just to have better
argument checks):

### Eclipse Workspace Patch 1.0
#P core
Index: src/org/apache/pivot/collections/ArrayList.java
===================================================================
--- src/org/apache/pivot/collections/ArrayList.java	(revision 1311663)
+++ src/org/apache/pivot/collections/ArrayList.java	(working copy)
@@ -573,6 +573,9 @@
     }

     private static void verifyIndexBounds(int index, int start, int end) {
+        if (end < start) {
+            throw new IllegalArgumentException(end + " < " + start);
+        }
         if (index < start || index > end) {
             throw new IndexOutOfBoundsException("index " + index + "
out of bounds [" + start + "," + end + "].");
         }


### Eclipse Workspace Patch 1.0
#P wtk
Index: src/org/apache/pivot/wtk/Component.java
===================================================================
--- src/org/apache/pivot/wtk/Component.java	(revision 1311663)
+++ src/org/apache/pivot/wtk/Component.java	(working copy)
@@ -2927,6 +2927,9 @@
      * @throws IndexOutOfBoundsException if index is out of range.
      */
     protected static final void indexBoundsCheck(String indexName,
int index, int min, int max) throws IndexOutOfBoundsException {
+        if (max < min) {
+            throw new IllegalArgumentException(max + " < " + min);
+        }
         if (index < min) {
             throw new IndexOutOfBoundsException(indexName + index + "
< " + min);
         }

and probably there are others ...

Ok, I know that this doesn't solve problems here, that is a (required)
second step.
After this simple change the exception would be:

java.lang.IllegalArgumentException: -1 < 0
	at org.apache.pivot.collections.ArrayList.verifyIndexBounds(ArrayList.java:577)
	at org.apache.pivot.collections.ArrayList.get(ArrayList.java:346)
	at org.apache.pivot.wtk.Container.get(Container.java:249)
	at org.apache.pivot.wtk.Window.isBottomMost(Window.java:1021)
	at org.apache.pivot.wtk.Window.clearActive(Window.java:961)
	at org.apache.pivot.wtk.Window.setParent(Window.java:485)
	at org.apache.pivot.wtk.Container.remove(Container.java:205)
	at org.apache.pivot.wtk.Container.remove(Container.java:179)
	at org.apache.pivot.wtk.Window.close(Window.java:736)
	at org.apache.pivot.tests.ActionMappingTest.shutdown(ActionMappingTest.java:62)
	at org.apache.pivot.wtk.DesktopApplicationContext.exit(DesktopApplicationContext.java:409)
	at org.apache.pivot.wtk.DesktopApplicationContext.exit(DesktopApplicationContext.java:394)
	at org.apache.pivot.wtk.DesktopApplicationContext$HostFrame.processWindowEvent(DesktopApplicationContext.java:236)
	at java.awt.Window.processEvent(Window.java:1822)
	at java.awt.Component.dispatchEventImpl(Component.java:4653)
	at java.awt.Container.dispatchEventImpl(Container.java:2097)
	at java.awt.Window.dispatchEventImpl(Window.java:2482)
	at java.awt.Component.dispatchEvent(Component.java:4481)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:648)
	at java.awt.EventQueue.access$000(EventQueue.java:84)
	at java.awt.EventQueue$1.run(EventQueue.java:607)
	at java.awt.EventQueue$1.run(EventQueue.java:605)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
	at java.awt.EventQueue$2.run(EventQueue.java:621)
	at java.awt.EventQueue$2.run(EventQueue.java:619)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:618)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

of course maybe a more detailed message would be better.


What do you think ?

Bye,
Sandro

Mime
View raw message