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

[apex] OperationWithLimitsInLoopRule missing other governor-limit consuming operations #3186

Open
jonathanwiesel opened this issue Mar 31, 2021 · 0 comments
Labels
a:false-negative PMD doesn't flag a problematic piece of code

Comments

@jonathanwiesel
Copy link
Contributor

jonathanwiesel commented Mar 31, 2021

Affects PMD Version:
6.33+
7.0.0

Description:

Currently the OperationWithLimitsInLoopRule rule verifies for some operations that count against Apex Governor Limits, but some of them are missing and therefore are not reported:

Instance methods 🚧 still to do

Static methods: ✔️ Note - these methods are already supported by #3198 with PMD 6.34.0

Other 🚧 still to do

Code Sample demonstrating the issue:

/**
 * @description X
 */
public with sharing class LoopLimits {
    
    /**
     * @description X
     */
    public static void checkLimits() {

        Http h = new Http();
        Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        Messaging.PushNotification msg = new Messaging.PushNotification();

        for (Integer i = 0; i < 10; i++) {

            h.send(new HttpRequest());

            Eventbus.publish(new Account__e()); //check only required for publish immediately events

            Approval.process(req);
            Approval.lock(new Account());
            Approval.unlock(new Account());

            Messaging.sendEmail(new Messaging.SingleEmailMessage[]{email});
            Messaging.renderEmailTemplate(null, null, null);
            Messaging.renderStoredEmailTemplate(null, null, null);

            new Contact().recalculateFormulas();
            
            System.enqueueJob(new MyQueueable());
            System.runAs(new User()) {
                System.debug(LoggingLevel.DEBUG, 'x');
            }
            System.schedule('x', '0 0 0 1 1 ?', new MySchedule());
            System.scheduleBatch(new MyBatch(), 'x', 1);

            msg.send('x', null);

            ConnectApi.Comment comment = ConnectApi.ChatterFeeds.getComment(null, null);
        }
    }
}

Steps to reproduce:

Please provide detailed steps for how we can reproduce the bug.

  1. Execute PMD over the above snippet, no operation inside the for-loop is reported although they all consume governor limits
@jonathanwiesel jonathanwiesel added the a:bug PMD crashes or fails to analyse a file. label Mar 31, 2021
@adangel adangel added a:false-negative PMD doesn't flag a problematic piece of code and removed a:bug PMD crashes or fails to analyse a file. labels Apr 2, 2021
@jsotuyod jsotuyod added the needs:pmd7-revalidation The issue hasn't yet been retested vs PMD 7 and may be stale label Mar 17, 2024
@jsotuyod jsotuyod removed the needs:pmd7-revalidation The issue hasn't yet been retested vs PMD 7 and may be stale label Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-negative PMD doesn't flag a problematic piece of code
Projects
None yet
Development

No branches or pull requests

3 participants