NPE protection in EntityMetadata and protective code for getting Resourc...

...es in a prd-per-resource environment.