Open thesunlover opened 1 year ago
@thesunlover , it's unfortunate that this error message is so uninformative. I'll see if I can follow that stack trace and reveal anything that might shed some light on this. Hopefully, I can do that on my end. I may end up asking you to do some debugging on your end if need be.
@thesunlover , okay, so I've done some chasing here.
Basically, the problem with this specific log seems to be:
AdapterController#createRecord
(defined at line 79) is determined to do a WRITE operation. So we have to walk that path to determine whether CRUD/FLS is respected.createRecord
calls a method.createRecord
) has an if
condition, and the path assumes that if
condition is unsatisfied. (i.e., the WRITE operation only occurs if this if
is unsatisfied)if
condition contains any CRUD/FLS checks. The attempt to do this causes an empty Optional
to be dereferenced, thus causing the error you're seeing.And that's about as far as I can get without looking at the code. If you can provide access to your codebase, I can try to crawl through it and see if I can locate the problematic if
. Otherwise, I can attempt to walk you through the process of how I'd do that debugging. It's up to you.
@jfeingold35 could you please elaborate on the sentence: "The attempt to do this causes an empty Optional to be dereferenced".
Looks like I could change the condition from read to write rule by switching the place of the CRUD operation to be inside the block of the if
.
@thesunlover , An Optional
is just a Java construct that encloses another type and can either contain an instance of that type or just be empty. They simplify null checks and prevent null pointer exceptions. The error here is that an Optional is unexpectedly empty and we're failing to properly account for that.
The operation specifically being a write operation is unlikely to be directly relevant to the cause of the bug. It's only worth mentioning because it might help you identify which specific if
expression is causing the bug. Once we know what that expression is, we can figure out why the Optional is empty and how to properly handle that.
Make sense?
Hey @jfeingold35, thank you again for the feedback and information you provided.
I see what you are saying. I'm falling into a loop from fixing one and getting the next error. IMO, we have all the required CRUD/FLS checks for the endpoints we are getting the errors, however, I would like to pass the security review from the 1st attempt.
Our company has agreed to share credentials to the repository, could you please contact me at salesforce-dev@interop.io?
Hey @jfeingold35,
could you please send me the details to (salesforce-dev@interop.io) on where to send you access to our repository?
I have created a case just in case you need to log your time. The case number in the partner's portal is 45574530
We haven't identified the root cause of the bug, but we've at least identified where the error is coming from. In code such as that attached, where you have a Map<String, Scheam.DescribeSObjectResult>
that you reference using a string of indeterminate value, then doing a CRUD/FLS check (e.g. isAccessible()
) using the associated DescribeSObjectResult
will cause a NoSuchElementException
as an empty optional is being dereferenced.
EntryPoint.cls
global with sharing class EntryPoint {
global static SObject entryPointMethod(String type) {
Schema.DescribeSObjectResult cDescribe = Constants.SUPPORTED_DESCRIBE_MAP.get(type);
if (!cDescribe.isAccessible()) { // This line causes the indicated error.
throw new PermissionsException('no perm');
}
SObject o = Database.query('SELECT Name FROM ' + type + ' LIMIT 1');
return o;
}
public class PermissionsException extends Exception {}
}
Constants.cls
public class Constants {
public static final List<String> SUPPORTED_SOBJECTS = new List<String> {
'account', 'contact'
};
public static final Map<String, SObjectType> GLOBAL_DESCRIBE = Schema.getGlobalDescribe();
public static final Map<String, Schema.DescribeSObjectResult> SUPPORTED_DESCRIBE_MAP = new Map<String,Schema.DescribeSObjectResult>();
static {
for (String sObjectName : SUPPORTED_SOBJECTS) {
Schema.SObjectType objType = GLOBAL_DESCRIBE.get(sObjectName);
if (objType != null) {
Schema.DescribeSObjectResult objDescription = objType.getDescribe();
SUPPORTED_DESCRIBE_MAP.put(sObjectName, objDescription);
}
}
}
}
This issue has been linked to a new work item: W-14463051
Describe the bug Unknown error logged into DFA report. DFA file is located here: https://gist.github.com/thesunlover/6cf1e5bab1acc98b8c1777fcc9cab031
There are 2 similar logs in the sfge.log file:
To Reproduce unknown
Expected behavior A clear log file or explanation about the issue that was found.
Screenshots N/A
Desktop (please complete the following information):
Additional context N/A
"Workaround": N/A
"Urgency": N/A