forcedotcom / sfdx-scanner

MIT License
214 stars 49 forks source link

[BUG] InternalExecutionError on assignment of inherited instance variables from abstract class #1406

Closed jaelee125 closed 4 months ago

jaelee125 commented 6 months ago

I'm not exactly sure what the issue is. SN_Constants class is a class we use to store constants. This class only has public static final String, Integer, Map, List, and Set.

Error and stacktrace: UnexpectedException: Undefined variable. key=mappingType, value=ApexStringValue{ value=Optional[Object]} ApexValue(ApexStringValue) {status=INITIALIZED, declarationVertex=ApexStringValue{ value=Optional.empty} ApexValue(ApexStringValue) {status=UNINITIALIZED, declarationVertex=Field{properties={FirstChild=false, BeginLine=50, Type=String, DefiningType_CaseSafe=sn_constants, LastChild=false, DefiningType=SN_Constants, EndLine=50, Name_CaseSafe=config_type_object, childIdx=24, BeginColumn=29, Name=CONFIG_TYPE_OBJECT}}, valueVertex=null, resolvedValues={}, returnedFrom=null, invocableExpression=null, method=null}, valueVertex=LiteralExpression{properties={FirstChild=true, BeginLine=50, DefiningType_CaseSafe=sn_constants, LastChild=false, DefiningType=SN_Constants, EndLine=50, Value=Object, childIdx=0, LiteralType=STRING, BeginColumn=50}}, resolvedValues={}, returnedFrom=null, invocableExpression=null, method=null}: com.salesforce.graph.symbols.MethodInvocationScope.updateVariable(MethodInvocationScope.java:114);com.salesforce.graph.symbols.AbstractClassInstanceScope.updateVariable(AbstractClassInstanceScope.java:129);com.salesforce.graph.symbols.PathScopeVisitor.updateVariable(PathScopeVisitor.java:190);com.salesforce.graph.symbols.PathScopeVisitor.afterVisit(PathScopeVisitor.java:1005);com.salesforce.graph.symbols.DefaultSymbolProviderVertexVisitor.afterVisit(DefaultSymbolProviderVertexVisitor.java:744);com.salesforce.graph.vertex.AssignmentExpressionVertex.afterVisit(AssignmentExpressionVertex.java:37)

jaelee125 commented 5 months ago

`public with sharing class SN_MetadataWrappers {

public abstract class ObjectsAndFieldsDefinitionWrapper extends MetadataWrapper {       
    @AuraEnabled public String type;
    @AuraEnabled public String networkObject;
}

public class ObjectDefinitionWrapper extends ObjectsAndFieldsDefinitionWrapper {

    public ObjectDefinitionWrapper(Map<String, Object> wrapperMap) {
        type = SN_Constants.CONFIG_TYPE_OBJECT;
        networkObject = (String) wrapperMap.get(NETWORK_OBJECT_KEY);
    }
}

}`

SN_MetadataWrappers.ObjectDefinitionWrapper objectWrapper = new SN_MetadataWrappers.ObjectDefinitionWrapper(objectMap);

The above fails. If I duplicate inherited instance variables in the class, it passes. Adding Engine Directives does not work for this error

"1","3","/Users/jae/code/specright-network/specright-network/main/default/classes/SN_Modules/SN_Settings/SN_SettingsController.cls","355","29","SN_SettingsController","getSpecrightNetworkTemplateMappings","","","","InternalExecutionError","Graph Engine identified your source and sink, but you must manually verify that you have a sanitizer in this path. Then, add an engine directive to skip the path. Next, create a Github issue for the Code Analyzer team that includes the error and stack trace. After we fix this issue, check the Code Analyzer release notes for more info. Error and stacktrace: UnexpectedException: Undefined variable. key=type, value=ApexStringValue{ value=Optional[Object]} ApexValue(ApexStringValue) {status=INITIALIZED, declarationVertex=ApexStringValue{ value=Optional.empty} ApexValue(ApexStringValue) {status=UNINITIALIZED, declarationVertex=Field{properties={FirstChild=false, BeginLine=52, Type=String, DefiningType_CaseSafe=sn_constants, LastChild=false, DefiningType=SN_Constants, EndLine=52, Name_CaseSafe=config_type_object, childIdx=25, BeginColumn=29, Name=CONFIG_TYPE_OBJECT}}, valueVertex=null, resolvedValues={}, returnedFrom=null, invocableExpression=null, method=null}, valueVertex=LiteralExpression{properties={FirstChild=true, BeginLine=52, DefiningType_CaseSafe=sn_constants, LastChild=false, DefiningType=SN_Constants, EndLine=52, Value=Object, childIdx=0, LiteralType=STRING, BeginColumn=50}}, resolvedValues={}, returnedFrom=null, invocableExpression=null, method=null}: com.salesforce.graph.symbols.MethodInvocationScope.updateVariable(MethodInvocationScope.java:114);com.salesforce.graph.symbols.AbstractClassInstanceScope.updateVariable(AbstractClassInstanceScope.java:129);com.salesforce.graph.symbols.PathScopeVisitor.updateVariable(PathScopeVisitor.java:190);com.salesforce.graph.symbols.PathScopeVisitor.afterVisit(PathScopeVisitor.java:1005);com.salesforce.graph.symbols.DefaultSymbolProviderVertexVisitor.afterVisit(DefaultSymbolProviderVertexVisitor.java:744);com.salesforce.graph.vertex.AssignmentExpressionVertex.afterVisit(AssignmentExpressionVertex.java:37)","https://developer.salesforce.com/docs/platform/salesforce-code-analyzer/guide/apexflsviolation-rule.html","InternalExecutionError","sfge"

jaelee125 commented 5 months ago

@sagar-j-sfdc Do you have any work arounds for this or any idea to get the engine directives to work for this issue?

jaelee125 commented 5 months ago

@jfeingold35 Any update on this?

jfeingold35 commented 5 months ago

Unfortunately, no updates at this time. We'll look into it and let you know once we have something. Thank you for your patience.

jfeingold35 commented 5 months ago

@jaelee125 , we're able to reproduce. It looks like the problem is that the scope of the child class isn't automatically receiving the properties inherited from the parent class. Unfortunately, the fix looks to be possibly non-trivial. We'll add it to our backlog, but in the meantime, if your workaround is unblocking you, we recommend continuing to use it.

git2gus[bot] commented 5 months ago

This issue has been linked to a new work item: W-15705191

jaelee125 commented 5 months ago

@jfeingold35 We currently don't have a workaround for this but we'll document it in the security review. Thanks

stephen-carter-at-sf commented 4 months ago

Marking this a duplicate of https://github.com/forcedotcom/sfdx-scanner/issues/1497