harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r495724 - in /harmony/enhanced/classlib/trunk/modules/awt/src: main/java/common/java/awt/event/KeyEvent.java test/api/java/common/java/awt/event/KeyEventTest.java
Date Fri, 12 Jan 2007 20:29:07 GMT
Author: hindessm
Date: Fri Jan 12 12:29:06 2007
New Revision: 495724

URL: http://svn.apache.org/viewvc?view=rev&rev=495724
Log:
Applied patches from "[#HARMONY-2406] [classlib][awt]
j.a.e.KeyEvent.getKeyText(int) thows StringIndexOutOfBoundsException
while RI doesn't".  Modified test case to follow project conventions for
exception handling.

Modified:
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/event/KeyEvent.java
    harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/event/KeyEventTest.java

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/event/KeyEvent.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/event/KeyEvent.java?view=diff&rev=495724&r1=495723&r2=495724
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/event/KeyEvent.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/event/KeyEvent.java
Fri Jan 12 12:29:06 2007
@@ -466,7 +466,7 @@
     }
 
     public static String getKeyText(int keyCode) {
-        String[] rawName = getPublicStaticFinalIntFieldName(keyCode, "VK_".length()); //$NON-NLS-1$
+        String[] rawName = getPublicStaticFinalIntFieldName(keyCode); //$NON-NLS-1$
 
         if ((rawName == null) || (rawName.length == 0)) {
             return ("Unknown keyCode: " + (keyCode >= 0 ? "0x" : "-0x") + //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
@@ -510,7 +510,7 @@
         return ("AWT." + name); //$NON-NLS-1$
     }
 
-    private static String[] getPublicStaticFinalIntFieldName(int value, int prefixLength)
{
+    private static String[] getPublicStaticFinalIntFieldName(int value) {
         Field[] allFields = KeyEvent.class.getDeclaredFields();
 
         try {
@@ -523,7 +523,9 @@
                         Modifier.isStatic(modifiers))
                 {
                     if (field.getInt(null) == value){
-                        return field.getName().substring(prefixLength).split("_"); //$NON-NLS-1$
+                        final String name = field.getName();
+                        final int prefixLength = name.indexOf("_") + 1;
+                        return name.substring(prefixLength).split("_"); //$NON-NLS-1$
                     }
                 }
             }

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/event/KeyEventTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/event/KeyEventTest.java?view=diff&rev=495724&r1=495723&r2=495724
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/event/KeyEventTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/event/KeyEventTest.java
Fri Jan 12 12:29:06 2007
@@ -26,13 +26,16 @@
 
 public class KeyEventTest extends TestCase {
 
-    public final void testGetKeyText() {
+    public final void testGetKeyText() throws StringIndexOutOfBoundsException {
         assertEquals(KeyEvent.getKeyText(KeyEvent.VK_1), "1");
         assertEquals(KeyEvent.getKeyText(KeyEvent.VK_SHIFT), "Shift");
         assertEquals(KeyEvent.getKeyText(KeyEvent.VK_INVERTED_EXCLAMATION_MARK),
                 "Inverted Exclamation Mark");
 //        assertTrue(KeyEvent.getKeyText(KeyEvent.VK_SEPARATOR).startsWith("NumPad ,"));
         assertEquals(KeyEvent.getKeyText(-16), "Unknown keyCode: -0x10");
+        
+        // Regression test for HARMONY-2406
+        KeyEvent.getKeyText(4);
     }
 
     public final void testGetKeyModifiersText() {



Mime
View raw message