Skip to content
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

[BUG] InternalExecutionError #1043

Closed
az-oolloow opened this issue Apr 4, 2023 · 4 comments
Closed

[BUG] InternalExecutionError #1043

az-oolloow opened this issue Apr 4, 2023 · 4 comments
Labels
BUG P3 Rarely Malfunction duplicate This issue or pull request already exists SFGE Issues related to the Salesforce Graph Engine

Comments

@az-oolloow
Copy link

Describe the bug
We got this error asking us to raise it on Github

Desktop (please complete the following information):

  • OS: [e.g. iOS] macOS 13.3
  • Scanner Version [e.g. 22] 3.10.0
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. this=ClassStaticScope{userClass=UserClass{properties={BeginLine=1, DefiningType_CaseSafe=promotionobjectivescontroller, DefiningType=PromotionObjectivesController, EndLine=1, FileName=/Users/alexzaytsev/Desktop/code/SalesForce/owSF/force-app/main/default/classes/PromotionObjectivesController.cls, Name_CaseSafe=promotionobjectivescontroller, BeginColumn=27, Name=PromotionObjectivesController}}} ClassStaticScope{, methodParametersStack=[MethodInvocationScope{invocableWithParameters=null, apexValues={}, returnedApexValue=null} com.salesforce.graph.symbols.MethodInvocationScope@d30de43]}, key=internalObjective, value=ApexValue(ApexBooleanValue) {status=INITIALIZED, declarationVertex=null, valueVertex=BooleanExpression{properties={FirstChild=false, Operator=!=, BeginLine=127, DefiningType_CaseSafe=promotionobjectivescontroller, LastChild=true, DefiningType=PromotionObjectivesController, EndLine=127, childIdx=1, BeginColumn=71}}, resolvedValues={}, returnedFrom=null, invocableExpression=null, method=null}: com.salesforce.graph.symbols.PathScopeVisitor.updateVariable(PathScopeVisitor.java:192);com.salesforce.graph.symbols.ClassStaticScope.updateVariable(ClassStaticScope.java:76);com.salesforce.graph.symbols.PathScopeVisitor.updateVariable(PathScopeVisitor.java:190);com.salesforce.graph.symbols.PathScopeVisitor.updateVariable(PathScopeVisitor.java:190);com.salesforce.graph.symbols.PathScopeVisitor.updateVariable(PathScopeVisitor.java:190);com.salesforce.graph.symbols.PathScopeVisitor.afterVisit(PathScopeVisitor.java:985)

So this is also a complex piece of code.

First, we have these models

public with sharing class PicklistDescriptor {
    @AuraEnabled public String label { get; set; }
    @AuraEnabled public String value { get; set; }
    @AuraEnabled public Boolean isDefault { get; set; }
}

public with sharing class SomethingOptions {
    @AuraEnabled public List<PicklistDescriptor> somethingPicklists { get; set; }
    @AuraEnabled public String somethingType { get; set; }

    @AuraEnabled public List<PicklistDescriptor> somethingElse { get; set; }

    @AuraEnabled public List<PicklistDescriptor> andOneMoreHere { get; set; }

    @AuraEnabled public Boolean whateverItIs { get; set; }
    @AuraEnabled public Boolean otherFlag { get; set; }
    @AuraEnabled public Boolean onemore { get; set; }
    @AuraEnabled public String someText { get; set; }
    @AuraEnabled public String moreText { get; set; }
    @AuraEnabled public String andMoreText { get; set; }

    @AuraEnabled public List<PicklistDescriptor> andAnotherBitHere { get; set; }
}

Then we have this code (since I had to replace all real class names and field names there may be some errors but let me know I will try to replicate)

@AuraEnabled(cacheable=false)
public static List<SomethingOptions> getMyOptions() {
    if (!Schema.SObjectType.Custom_Metadata_Type__mdt.isAccessible() ||
        !Schema.SObjectType.Custom_Metadata_Type__mdt.fields.Some_Field__c.isAccessible() ||
        !Schema.SObjectType.Custom_Metadata_Type_Two__mdt.isAccessible() ||
        !Schema.SObjectType.Custom_Metadata_Type_Two__mdt.fields.Id.isAccessible() ||
        !Schema.SObjectType.Custom_Metadata_Type_Two__mdt.fields.Label.isAccessible() ||
        !Schema.SObjectType.Custom_Metadata_Type_Two__mdt.fields.Some_Custom__c.isAccessible() ||
        !Schema.SObjectType.Custom_Metadata_Type_Two__mdt.fields.Some_Custom_Two__c.isAccessible() ||
        !Schema.SObjectType.Custom_Metadata_Type_Two__mdt.fields.Some_Custom_Three__c.isAccessible() ||
        !Schema.SObjectType.Custom_Object__c.isAccessible() ||
        !Schema.SObjectType.Custom_Object__c.fields.Picklist_Field__c.isAccessible() ||
        !Schema.SObjectType.Custom_Metadata_Type_Three__mdt.isAccessible() ||
        !Schema.SObjectType.Custom_Metadata_Type_Three__mdt.fields.Id.isAccessible() ||
        !Schema.SObjectType.Custom_Metadata_Type_Three__mdt.fields.Label.isAccessible() ||
        !Schema.SObjectType.Custom_Metadata_Type_Three__mdt.fields.Some_Custom__c.isAccessible() ||
        !Schema.SObjectType.Custom_Metadata_Type_Three__mdt.fields.Something__c.isAccessible() ||
        !Schema.SObjectType.Custom_Metadata_Type_Three__mdt.fields.Else__c.isAccessible() ||
        !Schema.SObjectType.Custom_Metadata_Type_Four__mdt.isAccessible() ||
        !Schema.SObjectType.Custom_Metadata_Type_Four__mdt.fields.Id.isAccessible() ||
        !Schema.SObjectType.Custom_Metadata_Type_Four__mdt.fields.Some_Custom__c.isAccessible() ||
        !Schema.SObjectType.Custom_Metadata_Type_Four__mdt.fields.Whatever__c.isAccessible() ||
        !Schema.SObjectType.Custom_Metadata_Type_Four__mdt.fields.Whatever_Two__c.isAccessible() ||
        !Schema.SObjectType.Custom_Metadata_Type_Four__mdt.fields.Whatever_Three__c.isAccessible() ||
        !Schema.SObjectType.Custom_Metadata_Type_Four__mdt.fields.Whatever_Four__c.isAccessible() ||
        !Schema.SObjectType.Custom_Metadata_Type_Four__mdt.fields.Whatever_Five__c.isAccessible() ||
        !Schema.SObjectType.Custom_Metadata_Type_Four__mdt.fields.Whatever_Six__c.isAccessible() ||
        !Schema.SObjectType.Custom_Metadata_Type_Four__mdt.fields.Whatever_Seven__c.isAccessible()
        ) {
        return new List<SomethingOptions>();
    }
    Custom_Metadata_Type__mdt[] exclusions = [SELECT Some_Field__c FROM Custom_Metadata_Type__mdt WITH USER_MODE LIMIT 1000];
    Set<String> excludes = new Set<String>();
    for (Custom_Metadata_Type__mdt variableName: exclusions) {
        if (variableName.Some_Field__c != null) {
            excludes.addAll(variableName.Some_Field__c.split(','));
        }
    }
    Custom_Metadata_Type_Two__mdt[] variablesTwo = [SELECT Id, Label, Some_Custom__c, Some_Custom_Two__c, Some_Custom_Three__c FROM Custom_Metadata_Type_Two__mdt WITH USER_MODE ORDER BY Some_Custom_Two__c LIMIT 50000];
    List<Custom_Metadata_Type_Two__mdt> variablesTwoResults = new List<Custom_Metadata_Type_Two__mdt>();
    for (Custom_Metadata_Type_Two__mdt variableTwo : variablesTwo) {
        if (!excludes.contains(variableTwo.Id) && !excludes.contains(variableTwo.Label) && !excludes.contains(variableTwo.Some_Custom_Two__c)) {
            variablesTwoResults.add(variableTwo);
        }
    }
    Custom_Metadata_Type_Three__mdt[] subTypes = [SELECT Id, Label, Some_Custom__c, Something__c, Else__c FROM Custom_Metadata_Type_Three__mdt WITH USER_MODE LIMIT 500];
    Map<String, SomethingOptions> result = new Map<String, SomethingOptions>();
    for(Custom_Metadata_Type_Two__mdt variableTwo : variablesTwoResults) {
        if (!result.containsKey(variableTwo.Some_Custom__c)) {
            SomethingOptions opt = new SomethingOptions();
            opt.somethingType = screen.Some_Custom__c;
            opt.somethingPicklists = new List<PicklistDescriptor>();
            opt.somethingElse = new List<PicklistDescriptor>();
            if (variableTwo.Some_Custom__c == 'ValueHere' || variableTwo.Some_Custom__c == 'OtherValue' || variableTwo.Some_Custom__c == 'ThirdValue') {
                List<Schema.PicklistEntry> picklists = Custom_Object__c.Picklist_Field__c.getDescribe().getPicklistValues();
                opt.andOneMoreHere = new List<PicklistDescriptor>();
                for (Schema.PicklistEntry p : picklists) {
                    PicklistDescriptor pd = new PicklistDescriptor();
                    pd.isDefault = p.isDefaultValue();
                    pd.label = p.getLabel();
                    pd.value = p.getValue();
                    opt.andOneMoreHere.add(pd);
                }
            } else if (variableTwo.Some_Custom__c == 'FourthValue') {
                if (Schema.SObjectType.Some_Other_Custom_Object__c.isAccessible() &&
                    Schema.SObjectType.Some_Other_Custom_Object__c.fields.Some_Other_Field__c.isAccessible()) {
                    List<Schema.PicklistEntry> picklists = Some_Other_Custom_Object__c.Some_Other_Field__c.getDescribe().getPicklistValues();
                    opt.andAnotherBitHere = new List<PicklistDescriptor>();
                    for (Schema.PicklistEntry p : picklists) {
                        PicklistDescriptor pd = new PicklistDescriptor();
                        pd.isDefault = p.isDefaultValue();
                        pd.label = p.getLabel();
                        pd.value = p.getValue();
                        opt.andAnotherBitHere.add(pd);
                    }
                }
            }
            result.put(variableTwo.Some_Custom__c, opt);
        }
        PicklistDescriptor descriptor = new PicklistDescriptor();
        descriptor.label = screen.Some_Custom_Three__c;
        descriptor.value = screen.Id;
        result.get(screen.Some_Custom__c).somethingPicklists.add(descriptor);
    }
    for(Custom_Metadata_Type_Three__mdt subType: subTypes) {
        if (result.containsKey(subType.Some_Custom__c)) { 
            PicklistDescriptor descriptor = new PicklistDescriptor();
            descriptor.value = subType.Something__c;
            descriptor.label = subType.Else__c;
            result.get(subType.Some_Custom__c).somethingElse.add(descriptor);
        }
    }
    Custom_Metadata_Type_Four__mdt[] fours = [SELECT Id, Label, Some_Custom__c, Whatever__c,
                                                Whatever_Two__c, Whatever_Three__c, Whatever_Four__c,
                                                Whatever_Five__c, Whatever_Six__c, Whatever_Seven__c FROM Custom_Metadata_Type_Four__mdt WITH USER_MODE LIMIT 500];
    for(Custom_Metadata_Type_Four__mdt four: fours) {
        if (!result.containsKey(four.Some_Custom__c)) {
            SomethingOptions opt = new SomethingOptions();
            opt.somethingType = four.Some_Custom__c;
            opt.somethingPicklists = new List<PicklistDescriptor>();
            opt.somethingElse = new List<PicklistDescriptor>();
            result.put(four.Some_Custom__c, opt);
        }
        result.get(four.Some_Custom__c).whateverItIs = four.Whatever__c != false; // <--- This is the line 127 in the error we receive
        result.get(four.Some_Custom__c).otherFlag = four.Whatever_Two__c;
        result.get(four.Some_Custom__c).onemore = four.Whatever_Five__c;
        result.get(four.Some_Custom__c).someText = four.Whatever_Three__c;
        result.get(four.Some_Custom__c).moreText = four.Whatever_Four__c;
        result.get(four.Some_Custom__c).andMoreText = four.Whatever_Six__c;
    }
    return result.values();
}
@az-oolloow az-oolloow changed the title [BUG] [BUG] InternalExecutionError Apr 4, 2023
@rmohan20
Copy link
Contributor

Hi @az-oolloow - thanks for letting us know and providing us with a mocked example.

From the stacktrace, looks like Graph Engine ran into a problem mapping a value for a variable called internalObjective. Almost looks like there's a reference to this variable before Graph Engine noted down its definition. The place it's complaining about is in PromotionObjectivesController, Line=127, Column=71.

Since your example has modified names, I'm not sure I have the full context. Could you refer to your code and give us more information:

  • Where is internalObjective defined?
  • What is its data type?
  • What modifiers does it have? (final, static, etc)
  • How is the value used?

A mocked example works well for us.

@az-oolloow
Copy link
Author

@rmohan20 I kind of highlighted that line in the mock up code that I pasted

result.get(four.Some_Custom__c).whateverItIs = four.Whatever__c != false; // <--- This is the line 127 in the error we receive

internalObjective is nothing more than a property on my class, in the mockup it correlates to whateverItIs

public with sharing class SomethingOptions {
    @AuraEnabled public Boolean whateverItIs { get; set; }
    }

@johnbelosf johnbelosf added the BUG P3 Rarely Malfunction label May 11, 2023
@git2gus
Copy link

git2gus bot commented May 11, 2023

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

@stephen-carter-at-sf stephen-carter-at-sf added the SFGE Issues related to the Salesforce Graph Engine label May 23, 2024
@stephen-carter-at-sf stephen-carter-at-sf added the duplicate This issue or pull request already exists label Jun 3, 2024
@stephen-carter-at-sf
Copy link
Collaborator

Marking this as a duplicate of #1497

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BUG P3 Rarely Malfunction duplicate This issue or pull request already exists SFGE Issues related to the Salesforce Graph Engine
Projects
None yet
Development

No branches or pull requests

4 participants