From 4f058ed24b97922bac10940d9d9fa9ae2be4a40f Mon Sep 17 00:00:00 2001 From: nirud Date: Sun, 28 Mar 2021 22:00:30 +0200 Subject: [PATCH] Fix NullPointerException after restart of Jenkins controller when agent resumes from suspend (#187) * Made field non transient and make sure it is not null * Made the map transient again to avoid serialization Co-authored-by: Rudolph, Nils --- src/main/java/com/microsoft/azure/vmagent/AzureVMCloud.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/microsoft/azure/vmagent/AzureVMCloud.java b/src/main/java/com/microsoft/azure/vmagent/AzureVMCloud.java index 1d3c2ed6..689dc748 100644 --- a/src/main/java/com/microsoft/azure/vmagent/AzureVMCloud.java +++ b/src/main/java/com/microsoft/azure/vmagent/AzureVMCloud.java @@ -132,7 +132,7 @@ public class AzureVMCloud extends Cloud { private List cloudTags; //The map should not be accessed without acquiring a lock of the map - private final transient Map agentLocks = new HashMap<>(); + private transient Map agentLocks = new HashMap<>(); private Supplier createAzureClientSupplier() { return Suppliers.memoize(() -> AzureClientUtil.getClient(credentialsId))::get; @@ -202,6 +202,10 @@ private Object readResolve() { instTemplates = null; } + if (agentLocks == null) { + agentLocks = new HashMap<>(); + } + // Walk the list of templates and assign the parent cloud (which is transient). ensureVmTemplateList(); for (AzureVMAgentTemplate template : vmTemplates) {