[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] FYI: Avoid recursion in java.util.Properties
From: |
Roman Kennke |
Subject: |
[cp-patches] FYI: Avoid recursion in java.util.Properties |
Date: |
Tue, 26 Jul 2005 16:27:00 +0200 |
User-agent: |
Mozilla Thunderbird 1.0.2 (X11/20050317) |
This fix 'outsources' the functionality of the getProperty methods into
a private method. This avoids infinite recursion if one of the
getProperty methods is overridden in subclasses.
2005-07-26 Roman Kennke <address@hidden>
* java/util/Properties.java
(getPropertyInternal): New method. Avoids infinite recursion if
getProperty() methods are overridden in subclasses.
(getProperty(String)): Use getPropertyInternal to avoid recursion.
(getProperty(String,String)): Likewise.
/Roman
Index: java/util/Properties.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/util/Properties.java,v
retrieving revision 1.30
diff -u -r1.30 Properties.java
--- java/util/Properties.java 25 Jul 2005 17:42:38 -0000 1.30
+++ java/util/Properties.java 26 Jul 2005 14:22:22 -0000
@@ -398,6 +398,30 @@
writer.flush ();
}
+
+ /**
+ * Internal method called by getProperty() methods. This avoids
+ * recursive calls if getProperty() methods are overwritten in
+ * a subclass.
+ *
+ * @param key the key for the property to fetch
+ * @param defaultValue the defaultValue or <code>null</code> if there
+ * is no default value
+ */
+ private String getPropertyInternal(String key, String defaultValue)
+ {
+ Properties prop = this;
+ // Eliminate tail recursion.
+ do
+ {
+ String value = (String) prop.get(key);
+ if (value != null)
+ return value;
+ prop = prop.defaults;
+ }
+ while (prop != null);
+ return defaultValue;
+ }
/**
* Gets the property with the specified key in this property list.
@@ -414,7 +438,7 @@
*/
public String getProperty(String key)
{
- return getProperty(key, null);
+ return getPropertyInternal(key, null);
}
/**
@@ -433,17 +457,7 @@
*/
public String getProperty(String key, String defaultValue)
{
- Properties prop = this;
- // Eliminate tail recursion.
- do
- {
- String value = (String) prop.get(key);
- if (value != null)
- return value;
- prop = prop.defaults;
- }
- while (prop != null);
- return defaultValue;
+ return getPropertyInternal(key, defaultValue);
}
/**
- [cp-patches] FYI: Avoid recursion in java.util.Properties,
Roman Kennke <=