Hi Java Ranch Experts,
Need your help. We�re trying to write out all values stored in the beans in our web application into a log file. We have a �writer� class that invokes all the getter methods within the beans. If the return type of the getter method is a String or primitive value, we log it. Otherwise, if an object (other than a String) is returned, the code then proceeds to invoke all the getter methods of that object (recursion). We�ve hit a problem wherein one of our beans returns a java.util.GregorianCalendar object, which has a getAvailableLocales() method that returns Locale[]. However, Locale class also has a getAvailableLocales() method that returns Locale[] leading to an infinite loop.
We�ve tried to stop recursion when the object being returned is the same as the containing class, and instead, return a �toString� to get a String value to log. However, at GregorianCalendar, the Locale[] array contains 140+ entries. Thus, the code will loop through each of this � it will then get to the fix to stop and return �toString�, but this still leads to 145x145 worth of values, generating an out of memory error.
We don�t really need the value of getAvailableLocales(), but if possible, we�d like to find a solution that won�t be specific to GregorianCalendar, since we�re expecting that this situation could occur for other classes as well.
Let me know if you have any idea to sort out this issue.
Any help will be much appreciated.
Thanks!