0

Does anyone know is there any option how to fix this PMD rule:

EmptyStatementBlock

in case when the error/violations/rule is reported for:

global override void finish(Database.BatchableContext bc) { }

I am pretty new in Salesforce so I am afraid to add or change some things related to batch because of possible code breaking.

Thanks in advance!

1 Answer 1

0

Add the following annotation to your code:

@SuppressWarnings('PMD.EmptyStatementBlock')

Example:

@SuppressWarnings('PMD.EmptyStatementBlock')
public override void finish(Database.BatchableContext bc) { }

This will disable the warning only for that method.

Note that public should generally be used for interface methods, unless you're making a Managed Package that needs this method to be global. Very few classes need global, and should not be marked as such unless necessary (e.g. WebService methods, @RemoteAction methods for iframe Visualforce pages, etc).

9
  • 2
    Worth noting that global is almost certainly the wrong access modifier to use here.
    – Adrian Larson
    Aug 16, 2021 at 17:47
  • Thanks for replying but unfortunately I should not use @SuppressWarnings (to disable the warning) in my case.
    – mhdev
    Aug 16, 2021 at 17:48
  • @AdrianLarson True enough. Edited.
    – sfdcfox
    Aug 16, 2021 at 17:49
  • 2
    @mhdev Told by whom? There are legitimate use cases for this annotation; it's an explicit mention that you know the method is empty, and you don't want the warning. If you really don't want to use it, you could put anything else in there, like Integer x = 0, but then you have to explain why you're using useless code. Suppressing one specific warning makes it explicit that you are aware of the problem, but there's no other "good" fix for it. You wouldn't want to, for example, disable this globally in your project.
    – sfdcfox
    Aug 16, 2021 at 17:57
  • 1
    @mhdev It's your code, you can do as you like, though if I were code reviewing you, I'd tell you to then remove the debug statements. They shouldn't be in production code.
    – sfdcfox
    Aug 16, 2021 at 18:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.