commons-lang icon indicating copy to clipboard operation
commons-lang copied to clipboard

[LANG-1524] : Added cycle detection check in toString for classes

Open aakashgupta96 opened this issue 4 years ago • 8 comments

  1. To String method earlier used to give stack overflow error in case of cyclic reference.
  2. Added a cycle detection check before calling toString recursively on type parameters. https://issues.apache.org/jira/browse/LANG-1524

aakashgupta96 avatar Nov 21 '20 01:11 aakashgupta96

@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.

aakashgupta96 avatar Nov 21 '20 01:11 aakashgupta96

rebase from master to solve the conflict

arturobernalg avatar Nov 21 '20 10:11 arturobernalg

Coverage Status

Coverage increased (+0.03%) to 95.016% when pulling 09a8e82048a9175abbcc52d79b190a93c609995c on aakashgupta96:feature/LANG-1524 into 764b9bba528487fb575b84766998086c24bb1f48 on apache:master.

coveralls avatar Nov 21 '20 11:11 coveralls

@arturobernalg @garydgregory Done rebasing changes with master. Can you please check now?

aakashgupta96 avatar Nov 22 '20 17:11 aakashgupta96

-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 avatar Nov 29 '20 19:11 garydgregory

@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?

aakashgupta96 avatar Nov 29 '20 20:11 aakashgupta96

@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 avatar Nov 29 '20 22:11 garydgregory

@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.

aakashgupta96 avatar Nov 29 '20 23:11 aakashgupta96