Executing a BDC refresh in specific cirsumstances causes a null pointer exception to be thrown by SharePoint.
Scenario #1:
- Add a BDC column without related columns to a list
- Add row(s) to the list and assign values to the BDC field
- Update the BDC column to use additional related fields
- Refresh the BDC column in the list
After clicking the refresh button and 'OK' on the next page, the next page displays a progress bar, then displays the following error: "An error occurred while retrieving data from
The log contains the following line:
Exception thrown while synchronizing business data System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.SharePoint.Portal.WebControls.BusinessDataSynchronizerJob.UpdateListItem(SPListItem item, BusinessDataField bizDataField, LobSystemInstance sysinst, Entity entity, View view, String[] secondaryBdcFieldNames, String[] secondaryWssFieldNames)
at Microsoft.SharePoint.Portal.WebControls.BusinessDataSynchronizerJob.DoWork()
Scenario #2
- Add a BDC column with related fields to a list
- Add row(s) to the list where the related fields have non-empty values
- Refresh the BDC column in the list
Scenario #3:
- Add a BDC column with related fields to a list
- Add row(s) to the list where the related fields have empty or null values
- Refresh the BDC column in the list
I'll contend that this is a bug for the following reason: reflecting on the Microsoft.SharePoint.Portal.WebControls.BusinessDataSynchronizerJob class that is throwing the exception yields a segment of code that checks the current value of the related field to the updated value retrieved from the BDC LineOfBusiness. If the two values are different, then it sets the item's value for that related field to the updated BDC value.
.NET Reflector gives the following code snippets that are useful:
Label_0144:
str = item[secondaryWssFieldNames[num2]].ToString();
str2 = Convert.ToString(instance.GetFormatted(field), CultureInfo.InvariantCulture);
if (!(str != str2))
{
goto Label_00F6;
}
goto Label_0113;
Label_0113:
flag = true;
item[secondaryWssFieldNames[num2]] = str2;
goto Label_00F6;
Label_001D:
if (flag)
{
item.Update();
}
Label_0144 creates str and str2 to compare the original (str) value and the updated (str2) value. If they are different, then Label_0113 sets the item's value to the updated value and sets Flag to true. Label001D checks the flag value and, if true, updates the item. This should only update items that have actually been updated.
(by the way, this is all SP1 code, post-Infrastructure update)
It seems a viable candidate for this null pointer exception would be the line str = item[secondaryWssFieldNames[num2]].ToString();. If the item's value is null, then the ToString() would obviously fail.
A quick PowerShell script shows that following scenario #1 above yields a null value for the related column. This is indeed a valid candidate for this issue.
If this is the case, has this been brought to Microsoft's attention? Is this addressed in any hotfix or update for SharePoint?