You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please, prefix the report title with the language it applies to within brackets, such as [java] or [apex]. If not specific to a language, you can use [core]
Rule Set:
6.0.0 Snapshoot
AvoidHardcodingId
Description:
15 digit number is indicated as Salesforce Id.
objAssetDevice.IMEI__c = '359040082913024';
Code Sample demonstrating the issue:
359040082913024 is not Salesforce Id but below code indicated as violation of AvoidHardcodingId
objAssetDevice.IMEI__c = '359040082913024';
While not a solution for the false positive scenario where a 15 digit string is considered a Salesforce ID, the current pattern could be made stricter.
Activity
rsoesemann commentedon Dec 5, 2017
@JAertgeerts didn't you add this rule. Can you make the regexp a bit smarter as describe here https://stackoverflow.com/questions/9742913/validating-a-salesforce-id?
jsotuyod commentedon Dec 5, 2017
@up2go-rsoesemann @JAertgeerts @parksungrin the rule is implemented based on this description which is actually a little more strict on 15 chars ids.
The rule is flawed for ids longer than 15 (it would allow, 16 and 17 chars "ids", and the 18 char ones are not validated).
However, for this scenario of a 15 char string, it would still match. I don't think we can safely detect this as a FP and avoid it...
rsoesemann commentedon Dec 5, 2017
The rule would need to incorporate also a checksum check as described here https://gist.github.com/jeriley/36b29f7c46527af4532aaf092c90dd56
A simple regex doesn't do the magic.
jsotuyod commentedon Dec 5, 2017
@up2go-rsoesemann that checksum applies only to 18 digit ids. 15 digit ids would still be flagged as long as the sixth position is a 0.
alan-morey commentedon Dec 16, 2017
While not a solution for the false positive scenario where a 15 digit string is considered a Salesforce ID, the current pattern could be made stricter.
pmd/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/errorprone/AvoidHardcodingIdRule.java
Line 13 in e7e5e13
The following pattern:
https://stackoverflow.com/a/29299786/264911
Also is
Pattern.CASE_INSENSITIVEflag redundant when the character classes are matching both upper and lower alpha?jsotuyod commentedon Dec 20, 2017
@alan-morey thanks, that's exactly what I was going after. The checksum check can be done too.
I'm flagging this for 6.1.0 release.
[apex] Stricter hardcoded ID detection
[-][apex] AvoidHardcodingId indicate 15 digit number as Id[/-][+][apex] AvoidHardcodingId false positives[/+]Update changelog, refs pmd#776
[apex] Add test case, refs #776
adangel commentedon Apr 24, 2018
Note: only solution for the specific string is right now to suppress the rule, like that: