Skip to content

Commit

Permalink
Fix NullPointerException after restart of Jenkins controller when age…
Browse files Browse the repository at this point in the history
…nt 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 <[email protected]>
  • Loading branch information
nirud and nilsrudolph authored Mar 28, 2021
1 parent 684ac23 commit 4f058ed
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/main/java/com/microsoft/azure/vmagent/AzureVMCloud.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public class AzureVMCloud extends Cloud {
private List<AzureTagPair> cloudTags;

//The map should not be accessed without acquiring a lock of the map
private final transient Map<AzureVMAgent, AtomicInteger> agentLocks = new HashMap<>();
private transient Map<AzureVMAgent, AtomicInteger> agentLocks = new HashMap<>();

private Supplier<Azure> createAzureClientSupplier() {
return Suppliers.memoize(() -> AzureClientUtil.getClient(credentialsId))::get;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 4f058ed

Please sign in to comment.