harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Anton Luht (JIRA)" <j...@apache.org>
Subject [jira] Created: (HARMONY-828) Preferences.nodeExists() throws IllegalArgumentException on a long path
Date Tue, 11 Jul 2006 09:10:30 GMT
Preferences.nodeExists() throws IllegalArgumentException on a long path
-----------------------------------------------------------------------

         Key: HARMONY-828
         URL: http://issues.apache.org/jira/browse/HARMONY-828
     Project: Harmony
        Type: Bug

  Components: Classlib  
 Environment: Windows XP Professional
    Reporter: Anton Luht
    Priority: Minor


Harmony: VM + classlib  revision 420760

According to 1.5 specs method throws  IllegalArgumentException - if the path name is invalid
(i.e., it contains multiple consecutive slash characters, or ends with a slash character and
is more than one character long). 

No limit for string length is specified.

RI returns false in this case.


import java.util.*;
import java.util.prefs.*;

public class test  {
    public static void main (String[] args) { 
        Preferences localPreferences = Preferences.userRoot();
                try {  
                String s ="ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd";
                System.out.println("len="+s.length());
                        System.out.println("res="+localPreferences.nodeExists(s));
                } catch (BackingStoreException e) {
                    e.printStackTrace();
            }
  } 
} 

Output on RI: 
len=81
res=false

Output on Harmony:
len=81
java.lang.IllegalArgumentException: Name length is too long: ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd
        at java.util.prefs.AbstractPreferences.getNodeFromBackend(AbstractPreferences.java:613)
        at java.util.prefs.AbstractPreferences.nodeImpl(AbstractPreferences.java:599)
        at java.util.prefs.AbstractPreferences.nodeExists(AbstractPreferences.java:651)
        at test.main(test.java:10)


-----------

The patch is quite simple:

Index: modules/prefs/src/main/java/java/util/prefs/AbstractPreferences.java
===================================================================
--- modules/prefs/src/main/java/java/util/prefs/AbstractPreferences.java
(revision 420760)
+++ modules/prefs/src/main/java/java/util/prefs/AbstractPreferences.java
(working copy)
@@ -648,8 +648,12 @@
                 startNode = this;
             }
         }
-        Preferences result = startNode.nodeImpl(name, false);
-        return null == result ? false : true;
+        try {
+          Preferences result = startNode.nodeImpl(name, false);
+          return null == result ? false : true;
+        } catch(IllegalArgumentException e) {
+          return false;
+        }
     }

     /*

------------------------

Please note that this patch doesn't break the validation functionality, because try/catch
doesn't wrap validateName(...)

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


Mime
View raw message