[SalesForce] Lightning : Illegal arguments error in java script server Side(Apex controller)

javascript side:

RemoveClick: function(component, event, helper) {
    var selCont = event.getParam("selectedJob");
    var conts = component.get("v.wrplst");
    var contsval = JSON.stringify(conts);
    alert('contsval value::::' + contsval);
    var Selndex = conts.indexOf(selCont);
    alert('selIndex value :::' + Selndex);
    var DeleteLen = conts.length;
    //alert('deleteLen value::::' + DeleteLen);
    var removeAction = component.get("c.removeRow");
    removeAction.setParams({
        "wrvalue": contsval,
        "rowval": Selndex,
    });
    removeAction.setCallback(this, function(g) {
        var state = g.getState();
        if (state == 'SUCCESS') {
            alert('success value');
        } else if (state === 'error') {
            alert('error value');
        }
    });
    $A.enqueueAction(removeAction);
}

server:

 @AuraEnabled
public static List <WrapperCriteria > removeRow(string wrvalue,integer rowval){
    system.debug('::::: rowToRemove val  :::::'+rowval);

  List < WrapperCriteria > warpList = (List < WrapperCriteria > ) JSON.deserialize(wrvalue, List<WrapperCriteria >.class);
    system.debug('::::::wrList value::::' + warpList);


    if(!string.isBlank(string.valueof(rowval)))   *//ERROR:Illegal arguments*
    {
        Action_Criteria__c acdelete = warpList[rowval].record;
        list<Action_Criteria__c> listAc = new list<Action_Criteria__c>();

        if(!string.isblank(acdelete.id))
        {
            Criteria_Master__c criteriaMaster = [select id,Name,Action_Criteria__c,(select id, Criteria_Master__c from Action_Criteria__r where id!=:acdelete.id ) from Criteria_Master__c where Id=:acdelete.Criteria_Master__c];
            listAc = [select id, Criteria_Master__c from Action_Criteria__c where id!=:acdelete.id and Criteria_Master__c=:acdelete.Criteria_Master__c];
            if(criteriaMaster.Action_Criteria__r.isEmpty())
            {
                criteriaMaster.Action_Criteria__c = false;
                update criteriaMaster;
            }
            delete acdelete;
        }
    }
    warpList.remove(rowval);
    system.debug('wraper List  *******'+warpList);
    return warpList;
} 

Best Answer

This is because there is a bug with Integer attribute type that ends up not being an Integer... You need to cast it to an Integer again:

rowval = Integer.valueOf(rowval);

This is a known issue, unfortunately not exposed on the Known Issue website.

I would suggest to create a Case and ask them to add it to bug W-2544431. The more we are to report it, the more likely they are going to fix it.