Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve TailRecursion inspection violations by replacing tail recursive calls #14814

Open
MANISH-K-07 opened this issue Apr 20, 2024 · 3 comments
Labels

Comments

@MANISH-K-07
Copy link
Contributor

MANISH-K-07 commented Apr 20, 2024

Follow-up of #14625

Version bump of IDEA to v2022.3.3 resulted in successful build with inspection problems that have been suppressed for migration :
https://app.circleci.com/pipelines/github/checkstyle/checkstyle/1/workflows/0968f80e-db8e-401a-ad87-8c409072ba31/jobs/574793/artifacts

In general recursion is not good and prone to failing eventually, some times in several decades :).

TailRecursion inspection problems need to be dealt with on a case by case basis.

<problems is_local_tool="true">
<problem>
<file>file://$PROJECT_DIR$/src/main/java/com/puppycrawl/tools/checkstyle/api/FullIdent.java</file>
<line>92</line>
<module>project</module>
<package>com.puppycrawl.tools.checkstyle.api</package>
<entry_point TYPE="method" FQNAME="com.puppycrawl.tools.checkstyle.api.FullIdent void extractFullIdent(com.puppycrawl.tools.checkstyle.api.FullIdent full, com.puppycrawl.tools.checkstyle.api.DetailAST ast)"/>
<problem_class id="TailRecursion" severity="ERROR" attribute_key="ERRORS_ATTRIBUTES">Tail recursion</problem_class>
<description>Tail recursive call <code>extractFullIdent()</code> #loc</description>
<highlighted_element>extractFullIdent</highlighted_element>
<language>JAVA</language>
<offset>16</offset>
<length>16</length>
</problem>

<problem>
<file>file://$PROJECT_DIR$/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/HiddenFieldCheck.java</file>
<line>656</line>
<module>project</module>
<package>com.puppycrawl.tools.checkstyle.checks.coding</package>
<entry_point TYPE="method" FQNAME="com.puppycrawl.tools.checkstyle.checks.coding.HiddenFieldCheck.FieldFrame boolean containsInstanceField(java.lang.String field)"/>
<problem_class id="TailRecursion" severity="ERROR" attribute_key="ERRORS_ATTRIBUTES">Tail recursion</problem_class>
<description>Tail recursive call <code>containsInstanceField()</code> #loc</description>
<highlighted_element>containsInstanceField</highlighted_element>
<language>JAVA</language>
<offset>30</offset>
<length>21</length>
</problem>

<problem>
<file>file://$PROJECT_DIR$/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/HiddenFieldCheck.java</file>
<line>668</line>
<module>project</module>
<package>com.puppycrawl.tools.checkstyle.checks.coding</package>
<entry_point TYPE="method" FQNAME="com.puppycrawl.tools.checkstyle.checks.coding.HiddenFieldCheck.FieldFrame boolean containsStaticField(java.lang.String field)"/>
<problem_class id="TailRecursion" severity="ERROR" attribute_key="ERRORS_ATTRIBUTES">Tail recursion</problem_class>
<description>Tail recursive call <code>containsStaticField()</code> #loc</description>
<highlighted_element>containsStaticField</highlighted_element>
<language>JAVA</language>
<offset>30</offset>
<length>19</length>
</problem>

<problem>
<file>file://$PROJECT_DIR$/src/main/java/com/puppycrawl/tools/checkstyle/checks/regexp/SinglelineDetector.java</file>
<line>114</line>
<module>project</module>
<package>com.puppycrawl.tools.checkstyle.checks.regexp</package>
<entry_point TYPE="method" FQNAME="com.puppycrawl.tools.checkstyle.checks.regexp.SinglelineDetector void checkLine(int lineNo, java.lang.String line, java.util.regex.Matcher matcher, int startPosition)"/>
<problem_class id="TailRecursion" severity="ERROR" attribute_key="ERRORS_ATTRIBUTES">Tail recursion</problem_class>
<description>Tail recursive call <code>checkLine()</code> #loc</description>
<highlighted_element>checkLine</highlighted_element>
<language>JAVA</language>
<offset>16</offset>
<length>9</length>
</problem>

<problem>
<file>file://$PROJECT_DIR$/src/main/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpCheck.java</file>
<line>326</line>
<module>project</module>
<package>com.puppycrawl.tools.checkstyle.checks.regexp</package>
<entry_point TYPE="method" FQNAME="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpCheck void findMatch()"/>
<problem_class id="TailRecursion" severity="ERROR" attribute_key="ERRORS_ATTRIBUTES">Tail recursion</problem_class>
<description>Tail recursive call <code>findMatch()</code> #loc</description>
<highlighted_element>findMatch</highlighted_element>
<language>JAVA</language>
<offset>16</offset>
<length>9</length>
</problem>

<problem>
<file>file://$PROJECT_DIR$/src/main/java/com/puppycrawl/tools/checkstyle/checks/annotation/SuppressWarningsCheck.java</file>
<line>316</line>
<module>project</module>
<package>com.puppycrawl.tools.checkstyle.checks.annotation</package>
<entry_point TYPE="method" FQNAME="com.puppycrawl.tools.checkstyle.checks.annotation.SuppressWarningsCheck void walkConditional(com.puppycrawl.tools.checkstyle.api.DetailAST cond)"/>
<problem_class id="TailRecursion" severity="ERROR" attribute_key="ERRORS_ATTRIBUTES">Tail recursion</problem_class>
<description>Tail recursive call <code>walkConditional()</code> #loc</description>
<highlighted_element>walkConditional</highlighted_element>
<language>JAVA</language>
<offset>12</offset>
<length>15</length>
</problem>

<problem>
<file>file://$PROJECT_DIR$/src/test/java/com/puppycrawl/tools/checkstyle/utils/ModuleReflectionUtilTest.java</file>
<line>390</line>
<module>project</module>
<package>com.puppycrawl.tools.checkstyle.utils</package>
<entry_point TYPE="method" FQNAME="com.puppycrawl.tools.checkstyle.utils.ModuleReflectionUtilTest.InvalidNonDefaultConstructorClass void method(int data)"/>
<problem_class id="TailRecursion" severity="ERROR" attribute_key="ERRORS_ATTRIBUTES">Tail recursion</problem_class>
<description>Tail recursive call <code>method()</code> #loc</description>
<highlighted_element>method</highlighted_element>
<language>JAVA</language>
<offset>16</offset>
<length>6</length>
</problem>
</problems>

A probable solution would be to replace tail recursive calls with more reliable approach such as looping, to increase speed and optimization that is omitted by recursions.

PS: The line numbers shown in xml might be outdated. Please find by class names and reference entry points.

@MANISH-K-07
Copy link
Contributor Author

@romani , we should maybe deal with checks first and later discuss about the api class and utils test class? What do you feel?

@MANISH-K-07
Copy link
Contributor Author

@romani , @nrmancuso , #14815 is merged, could you please review and approve this issue if you agree..

@nrmancuso
Copy link
Member

Let's go!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants