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] AvoidGlobalModifierRule gives warning even when its a webservice - false positive #1348

Closed
pranayjswl007 opened this Issue Sep 13, 2018 · 5 comments

Comments

Projects
None yet
4 participants
@pranayjswl007

pranayjswl007 commented Sep 13, 2018

Affects PMD Version: ALL

Rule: AvoidGlobalModifierRule

Description: When its a webservice , it will be declared as global. Even in that case it is causing warning. The rule should be smart enough to understand that its an exposed webservice and can be global

Code Sample demonstrating the issue:

@RestResource(urlMapping = '/partners/submit/*')
global class Generic_LoanCreation {
	@HttpPost
	global static void createLoanApplication() {
	
	}
}

Running PMD through: * Ant*

@adangel

This comment has been minimized.

Member

adangel commented Sep 14, 2018

Thanks for the report.

Is it a requirement, that REST service classes need to be global? I've seen that the code samples in the Apex documentation, the classes are global there too, but I didn't see a clear statement, that they must be global. The same applies then for SOAP web services.

@JAertgeerts

This comment has been minimized.

Contributor

JAertgeerts commented Sep 15, 2018

@adangel adangel changed the title from [apex]AvoidGlobalModifierRule gives warning even when its a webservice. False positive to [apex] AvoidGlobalModifierRule gives warning even when its a webservice. False positive Sep 17, 2018

@adangel

This comment has been minimized.

Member

adangel commented Sep 17, 2018

Thanks for checking!

Apparently, for SOAP webservices, similar rules apply:

All classes that contain methods defined with the webservice keyword must be declared as global.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_web_services_methods_considerations.htm

@adangel adangel changed the title from [apex] AvoidGlobalModifierRule gives warning even when its a webservice. False positive to [apex] AvoidGlobalModifierRule gives warning even when its a webservice - false positive Sep 17, 2018

adangel added a commit to adangel/pmd that referenced this issue Sep 17, 2018

@adangel adangel added the has:pr label Sep 17, 2018

@adangel adangel added this to the 6.8.0 milestone Sep 17, 2018

@rsoesemann

This comment has been minimized.

Contributor

rsoesemann commented Sep 17, 2018

Sorry for stepping in to late but I think instead of changing the rule such an issue should be ignored when global must be used.

The use of global always has risks (being unable to change the signature later, delete class from package,...). PMD for Apex is not a syntax checker it's a tool that warns developer to no misuse syntactically correct features of Apex.

@adangel

This comment has been minimized.

Member

adangel commented Sep 18, 2018

For a Java rule, we usually add such exceptions to the rule, so that you don't need to configure suppressions/exclusions.

IMHO there is no other way than using global classes/methods, when implementing a webservice in Apex. That's why I consider this a valid false-positive.
If there is a way, we should change the description of the rule and point towards the alternative implementation for webservices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment