commons-lang
commons-lang copied to clipboard
[LANG-1524] : Added cycle detection check in toString for classes
- To String method earlier used to give stack overflow error in case of cyclic reference.
- Added a cycle detection check before calling toString recursively on type parameters. https://issues.apache.org/jira/browse/LANG-1524
@arturobernalg @garydgregory Could you please review this PR? Since I'm new to open source, let me know in case I missed something or I need to make any changes.
rebase from master to solve the conflict
Coverage increased (+0.03%) to 95.016% when pulling 09a8e82048a9175abbcc52d79b190a93c609995c on aakashgupta96:feature/LANG-1524 into 764b9bba528487fb575b84766998086c24bb1f48 on apache:master.
@arturobernalg @garydgregory Done rebasing changes with master. Can you please check now?
-1: A better and proper fix would actually return a String. If can the test code compiles, then the API call should return a "Java-esque" String per the Javadoc.
@garydgregory According to me, we cannot represent the cyclic dependency in extended string form, hence I thought it would be better to detect this kind of scenario and then throw an exception in order to avoid cyclic method calls and StackOverflow Exception.
Can you please suggest how the 'java-esque' string would look like?
@garydgregory According to me, we cannot represent the cyclic dependency in extended string form, hence I thought it would be better to detect this kind of scenario and then throw an exception in order to avoid cyclic method calls and StackOverflow Exception.
Can you please suggest how the 'java-esque' string would look like?
In the Eclipse debugger, AAAAClass.BBBBClass.CCCClass.class
is displayed as "class org.apache.commons.lang3.reflect.AAAAClass$BBBBClass$CCCClass". We don't display the class
prefix IIRC. I do not know if Eclipse does not display generics because it never does or because doing so in this case is problematic.
@garydgregory I agree that the problem is coming only because TypeUtils Class is trying to display the information of type parameters too. Java as language allows having type parameters on inner nested classes too, but we surely can't display type information in these scenarios where we have circular reference.
Both IntelliJ and Eclipse don't show type information for the classes and hence they never go in that cyclic loop which java as language supports.